Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usage? #1

Closed
webface opened this issue Apr 27, 2014 · 21 comments
Closed

usage? #1

webface opened this issue Apr 27, 2014 · 21 comments

Comments

@webface
Copy link

webface commented Apr 27, 2014

how do you use and retrieve data from this field type?

@draison
Copy link

draison commented May 6, 2014

Looking for the same answer. Anyone?

@webface
Copy link
Author

webface commented May 6, 2014

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!!!

@coreymcollins
Copy link
Contributor

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!

@webface
Copy link
Author

webface commented May 9, 2014

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',
        ),

    ),
);

@webface webface closed this as completed May 9, 2014
@webface webface reopened this May 9, 2014
@webface
Copy link
Author

webface commented May 9, 2014

It occurs on the back end. I havent tried cmb fields on the front end yet

@coreymcollins
Copy link
Contributor

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!

@webface
Copy link
Author

webface commented May 12, 2014

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

screen shot 2014-05-12 at 11 44 08 am

@draison
Copy link

draison commented May 15, 2014

Same problem here, I just have a list of posts and I can do anything with them. I can move, select or deselect them.

@webface
Copy link
Author

webface commented May 26, 2014

I still cant get it to work. Any ideas. It just lists the posts. They are not selectable or draggable

@webface
Copy link
Author

webface commented May 28, 2014

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.

@webface webface closed this as completed May 28, 2014
@webface webface reopened this May 28, 2014
@webface
Copy link
Author

webface commented May 28, 2014

I can drag and drop but its not saving any data. Lets dig in some more

@draison
Copy link

draison commented May 29, 2014

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.

@jajouka79
Copy link

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

@adhik
Copy link

adhik commented Aug 20, 2014

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:
error

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

@schemedesigns
Copy link

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.

@tw2113
Copy link

tw2113 commented Nov 19, 2014

@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?

@schemedesigns
Copy link

@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.

meta_boxes

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!

@jtsternberg
Copy link
Member

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.

@schemedesigns
Copy link

@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!

@tw2113
Copy link

tw2113 commented Nov 20, 2014

Good to hear you have a possible alternative solution to your original attempts @schemedesigns

@fysalyaqoob
Copy link

i am not getting post conetent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants