CMB2 / cmb2-attached-posts

Custom field for CMB2 for attaching posts to a page.
GNU General Public License v2.0
135 stars 62 forks source link

Search data append wrong #35

Open thinhbg59 opened 7 years ago

thinhbg59 commented 7 years ago

Hi Team, Thank you for your plugin. I have one issue: I using two field with type: custom_attached_posts When I click the search button and select the data, I see the value returned is showing the wrong position. You can see a screenshot I attached below. http://prntscr.com/dziula Thanks

jtsternberg commented 7 years ago

Yah, unfortunately the feature wasn't intended to work with more than one attached-posts field on the page. Definitely a bug. Will have to update when I get a chance.

thinhbg59 commented 7 years ago

Thanks for response very quickly. I'll wait until it gets updated.

DizzyBHigh commented 7 years ago

Any News on this? am having the same issue with 2 attached post fields for adding content. Only happens when the search button on the first field is used, it adds it to the second field. is there anyway to increase the number of entries displayed inn a list to avoid the search completely?

technotarek commented 7 years ago

The problem, as described above, resides only in the Search feature. With that in mind, there is a workaround. Set the Custom Attached Post field's query args 'post_per_page' parameter to -1, which will remove the limit on the number of posts in the initial Available Posts frame. That is, every single post from your site will appear in the initial window, so you never have to use the Search component.

Beware! This may be problematic depending on the size of your site and your server or browser. If you have thousands of posts, this could cripple your database server or the WordPress UI in your browser. You can help prevent against this by using additional query arguments to reduce the number of results returned.

Here is an example using posts_per_page, post_type, and category_name arguments.

$my_field->add_field( array(
    'name'    => __( 'Attached Posts', 'cmb2' ),
    'desc'    => __( 'Drag posts from the left column to the right column to attach them to this post.', 'cmb2' ),
    'id'      => 'attached_posts',
    'type'    => 'custom_attached_posts',
    'options' => array(
      'show_thumbnails' => true, // Show thumbnails on the left
      'filter_boxes'    => true, // Show a text box for filtering the results
      'query_args'      => array(
        'posts_per_page' => -1,
        'post_type'      => 'post',
        'category_name'  => 'videos'
      ), // override the get_posts args
    ),
  ) );
erikberger commented 6 years ago

This pull request is a fix for this issue: https://github.com/CMB2/cmb2-attached-posts/pull/41 .