Giter Site home page Giter Site logo

lmartins / cmb2-attached-posts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cmb2/cmb2-attached-posts

0.0 1.0 0.0 165 KB

Custom field for Custom Metaboxes and Fields for WordPress for attaching posts to a page.

License: GNU General Public License v2.0

PHP 54.58% CSS 11.35% JavaScript 34.07%

cmb2-attached-posts's Introduction

CMB2 Attached Posts Field

Custom field for CMB2.

The post IDs are saved in an array, which can be rearranged by dragging and dropping posts in the attached posts column.

If the ability to search for a post and attach it is more in line with what you need, you might consider CMB2 Post Search field instead.

Installation

Follow the example in example-field-setup.php for a demonstration. The example assumes you have both CMB2 and this extension in your mu-plugins directory. If you're using CMB2 installed as a plugin, remove line 6 of the example.

Customization

In the example file example-field-setup.php, the field is added using the prefix _attached_cmb2_ and the name attached_posts which results in a meta key of _attached_cmb2_attached_posts. The example also demonstrates how to modify the get_posts query args.

Usage

You can retrieve the meta data using the following:

$attached = get_post_meta( get_the_ID(), '_attached_cmb2_attached_posts', true );

This will return an array of attached post IDs. You can loop through those post IDs like the following example:

foreach ( $attached as $attached_post ) {
	$post = get_post( $attached_post );
}

Once you have the post data for the post ID, you can proceed with the desired functionality relating to each attached post.

cmb2-attached-posts's People

Contributors

camdensegal avatar clifgriffin avatar coreymcollins avatar jtsternberg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.