Git Product home page Git Product logo

Comments (21)

draison avatar draison commented on July 23, 2024

Looking for the same answer. Anyone?

from cmb2-attached-posts.

webface avatar webface commented on July 23, 2024

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.

coreymcollins avatar coreymcollins commented on July 23, 2024

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.

webface avatar webface commented on July 23, 2024

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.

webface avatar webface commented on July 23, 2024

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

from cmb2-attached-posts.

coreymcollins avatar coreymcollins commented on July 23, 2024

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.

webface avatar webface commented on July 23, 2024

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

from cmb2-attached-posts.

draison avatar draison commented on July 23, 2024

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.

webface avatar webface commented on July 23, 2024

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

from cmb2-attached-posts.

webface avatar webface commented on July 23, 2024

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.

webface avatar webface commented on July 23, 2024

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

from cmb2-attached-posts.

draison avatar draison commented on July 23, 2024

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.

jajouka79 avatar jajouka79 commented on July 23, 2024

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.

adhik avatar adhik commented on July 23, 2024

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

from cmb2-attached-posts.

schemedesigns avatar schemedesigns commented on July 23, 2024

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.

tw2113 avatar tw2113 commented on July 23, 2024

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

schemedesigns avatar schemedesigns commented on July 23, 2024

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

from cmb2-attached-posts.

jtsternberg avatar jtsternberg commented on July 23, 2024

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.

schemedesigns avatar schemedesigns commented on July 23, 2024

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

tw2113 avatar tw2113 commented on July 23, 2024

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

from cmb2-attached-posts.

fysalyaqoob avatar fysalyaqoob commented on July 23, 2024

i am not getting post conetent

from cmb2-attached-posts.

Related Issues (20)

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.