Comments (21)
Looking for the same answer. Anyone?
from cmb2-attached-posts.
I figured out the usage:
array(
'name' => __( 'Test', 'cmb' ),
'desc' => __( 'Test', 'cmb' ),
'id' => $prefix . 'test',
'type' => 'custom_attached_posts',
),
However the plugin appears to be broken:
**Warning: in_array() expects parameter 2 to be array, string given in /site/wp-content/plugins/cmb-attached-posts-master/attached-posts-field.php on line 52
Coreymcollins: Help!!!
from cmb2-attached-posts.
Hey Hey! Sorry for the delay in response, guys.
I added a usage example, so if you're still having questions you can check that out.
webface - I'm not getting that error at all. Can you let me know where that's happening for you? I didn't receive it on the front-end or back-end, and even moved all of my posts to draft mode to ensure that no posts would be found. I received no error on that line.
draison, do you happen to receive the same error as webface is reporting above?
Any info you can give me would be great!
from cmb2-attached-posts.
Corey I'm still getting the error. I down loaded the latest Custom-Metaboxes-and-Fields-for-WordPress-master and updated your plugin but i still get the same result.
Warning: in_array() expects parameter 2 to be array, string given in /_mampsites/equinelle/wp-content/plugins/equinelleCMS/lib/cmb-attached-posts-master/attached-posts-field.php on line 52
Hello world!
Im using the following code..
$prefix = 'eqc';
/**
* Sample metabox to demonstrate each field type included
*/
$meta_boxes['Tester'] = array(
'id' => 'test_meta_box',
'title' => __( 'Test metabox', 'cmb' ),
'pages' => array( 'page' ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
// 'cmb_styles' => true, // Enqueue the CMB stylesheet on the frontend
'fields' => array(
array(
'name' => __( 'Test', 'cmb' ),
'desc' => __( 'Test', 'cmb' ),
'id' => $prefix . 'atp',
'type' => 'custom_attached_posts',
),
),
);
from cmb2-attached-posts.
It occurs on the back end. I havent tried cmb fields on the front end yet
from cmb2-attached-posts.
Bingo, found it - the issue was occurring on new pages without any posts attached yet. The $attached array was empty, so attempting to check it for values was failing. Pushed a fix, let me know if this does the trick for ou!
from cmb2-attached-posts.
I dont get an error anymore. It just lists the posts in the field and I cant do anything with them. I cant move, select or deselect them
from cmb2-attached-posts.
Same problem here, I just have a list of posts and I can do anything with them. I can move, select or deselect them.
from cmb2-attached-posts.
I still cant get it to work. Any ideas. It just lists the posts. They are not selectable or draggable
from cmb2-attached-posts.
Problem solved. I looked through the code again and noticed that the javascript and css files in the plugin are not being loaded. I added them myself with the following code and presto.. plugin comes to life.
function attached_post_scripts(){
wp_enqueue_script("jquery");
wp_enqueue_script( 'jquery-ui', plugin_dir_url( __FILE__ ) . 'js/lib/jquery-ui-1.10.4.custom.min.js', array('jquery'), null );
wp_enqueue_script( 'attached_posts_init', plugin_dir_url( __FILE__ ) . 'js/attached-posts.js', array( 'jquery-ui' ), null );
wp_enqueue_style( 'attached_posts_css', plugin_dir_url( __FILE__ ) . 'css/attached-posts-admin.css', array(), null );
}
add_action( 'admin_init', 'attached_post_scripts' );
This plugin is great. Excellent work Cory. Draison hope this helps.
from cmb2-attached-posts.
I can drag and drop but its not saving any data. Lets dig in some more
from cmb2-attached-posts.
Thanks webface, the drag & drop function working now but like you I can't save any data. I will inspect the problem when i will have time. I'm a little busy with other works now. But your help is really appreciated.
+1 to you.
from cmb2-attached-posts.
Hi , I have tried to setup this custom field to no avail. All the files are loading but the field is missing. Here is the code that I have used :-
function wpb_initialize_cmb_meta_boxes() {
if ( ! class_exists( 'cmb_Meta_Box' ) ):
require_once(plugin_dir_path( FILE ) . 'init.php');
require_once(plugin_dir_path( FILE ) . 'cmb-field-select2-master/cmb-field-select2.php');
require_once(plugin_dir_path( FILE ) . 'cmb-attached-posts-master/attached-posts-field.php');
endif;
}
add_action( 'init', 'wpb_initialize_cmb_meta_boxes', 9999 );
function attached_post_scripts(){
wp_enqueue_script("jquery");
wp_enqueue_script( 'jquery-ui', plugin_dir_url( FILE ) . 'cmb-attached-posts-master/js/lib/jquery-ui-1.10.4.custom.min.js', array('jquery'), null );
wp_enqueue_script( 'attached_posts_init', plugin_dir_url( FILE ) . 'cmb-attached-posts-master/js/attached-posts.js', array( 'jquery-ui' ), null );
wp_enqueue_style( 'attached_posts_css', plugin_dir_url( FILE ) . 'cmb-attached-posts-master/css/attached-posts-admin.css', array(), null );
}
add_action( 'admin_init', 'attached_post_scripts' );
and the field is in a metabox using the following code:
array(
'name' => __( 'Test', 'cmb' ),
'desc' => __( 'Test', 'cmb' ),
'id' => $prefix . 'atp',
'type' => 'custom_attached_posts',
),
When I look at the edit post page in wordpress the field is missing, thanks
from cmb2-attached-posts.
Hi there,
I was unable to save the data too.
It turned out that the input hidden's name attribute was always using '_attached_posts[]' on it's name attribute instead of the specific id that I choose:
For quick solution, just use '_attached_posts' for 'id' attribute while specifying this field:
array(
'name' => __('Add Subnavigation', 'test'),
'desc' => __('Choose one or more subnavigation.', 'test'),
'id' => '_attached_posts',
'type' => 'custom_attached_posts',
),
I believe we need to fix 'js/attached-posts.js' for a better solution.
Corey: Thanks for the nice code
from cmb2-attached-posts.
Hi guys, I am wondering if there has been a solution to this issue yet? I am trying to use the attached posts field to allow the client to pick a "next" and "previous" post but because of not being able to specify unique ids for the meta box I can't use two meta boxes for one post. Thanks.
from cmb2-attached-posts.
@schemedesigns we're trying to figure out your use case and what you mean by "allow the client to pick a 'next' and 'previous' post". Is this something that you want to be part of the UI for the backend as they're doing administration? Something on the frontend when viewing the site?
from cmb2-attached-posts.
@tw2113 Thank you for getting back to me. Sorry for being a little unclear. I will clarify a bit. What I am trying to create for my client is a presentation tool (think PowerPoint). Each page/post is a slide. On the frontend on the bottom of each slide are three navigation buttons "Previous slide", "Next slide" and "home". What I was hoping to achieve is to have two meta boxes on the backend where the client could pick which page/post the "next slide" and "Previous slide" buttons link to on each slide. I was hoping to have something like the attached screenshot on the backend.
When setting up my meta boxes I have done the following
array(
'name' => __( 'Next Page', 'scheme-presentations' ),
'desc' => __( 'This is where you specify the next page in the document navigation.', 'scheme-presentations' ),
'id' => $prefix . 'next_post',
'type' => 'custom_attached_posts',
),
array(
'name' => __( 'Previous Page', 'scheme-presentations' ),
'desc' => __( 'This is where you specify the previous page in the document navigation.', 'scheme-presentations' ),
'id' => $prefix . 'previous_post',
'type' => 'custom_attached_posts',
)
When calling it in my template I would do so like this:
$attached = get_post_meta( get_the_ID(), '_schemepres_next_post', true );
echo '<li><a href="' . get_permalink( $attached[0] ) . '">Next</a></li>';`
I hope this clarifies a bit. Thank you!
from cmb2-attached-posts.
You may want to look into this field-type instead: https://github.com/WebDevStudios/CMB2-Post-Search-field
It'll allow you to do multiple fields.
from cmb2-attached-posts.
@jtsternberg Thanks for the suggestion. That actually got me thinking and ended up following this example to create two dropdown menus. Thanks for the help!
from cmb2-attached-posts.
Good to hear you have a possible alternative solution to your original attempts @schemedesigns
from cmb2-attached-posts.
i am not getting post conetent
from cmb2-attached-posts.
Related Issues (20)
- The “show_on” filter doesn’t work in attaching posts with CMB2 HOT 1
- Allow search button to be hidden HOT 1
- Retrieving meta key value instead of ID HOT 2
- Create a better experience when there are no posts to select from
- Post type list display if there been attachment to post or not HOT 2
- There is a bug with sorting inside the group
- Attach Woocommerce Products HOT 1
- Custom column titles? HOT 2
- Reciprocal Relationships? HOT 4
- Min/max options HOT 3
- Deleting Attached Posts Creates Error within Custom Field
- Customize post titles
- Related posts in checkbox list HOT 2
- PHP Warning: Use of undefined constant CMB2_ATTACHED_POSTS_FIELD_VERSION HOT 2
- Search button does not load just custom post type posts HOT 1
- ERR_NAME_NOT_RESOLVED in the console
- Implement data store as Pivot Table
- Multiple post types issue HOT 1
- add number/text to each post
- Compatibility issue with repeatable fields HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cmb2-attached-posts.