- This topic has 12 replies, 2 voices, and was last updated 6 years, 2 months ago by
Steve.
-
AuthorPosts
-
-
November 11, 2015 at 11:29 am #4925
tatamataMemberHi,
any idea why this metabox is not saving data?
<?php /* Title: Best of band Description: Pick and order tours for frontpage display Post type: page Context: normal Priority: high Order: 1 Locked: true Meta box: false */ $args = array( 'post_type' => 'tour', 'tax_query' => array( array( 'taxonomy' => 'traka_taxo', 'field' => 'slug', 'terms' => 'best-of', ), ), ); $best_of_choices = array(); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) : $query->the_post(); $best_of_choices[] = array("post_id" => get_the_ID(), "post_name" => get_the_title()); endwhile; wp_reset_postdata(); } else { _e( 'Sorry, no posts matched your criteria.' ); } piklist('field', array( 'type' => 'group', 'scope' => 'post_meta', 'label' => __('Best of - on Frontpage', 'raftrek'), 'description' => __('Order of Best of tours for frontpage display.', 'raftrek'), 'field' => 'best_of_frontpage', 'add_more' => false, 'fields' => array( array( 'type' => 'group', 'field' => 'grupa_best_of', 'add_more' => true, 'fields' => array( array( 'type' => 'select', 'field' => 'best_of_post_id', 'label' => __('Tour Title', 'raftrek'), 'columns' => 12, 'choices' => piklist($best_of_choices, array('post_id','post_name')) ) ) ) ) ));other metaboxes tied to custom post type save normaly.
-
November 11, 2015 at 11:30 am #4926
tatamataMemberusing piklist 0.9.9.6
other metaboxes tied to custom post type save normaly.
-
November 12, 2015 at 11:31 am #4936
-
November 12, 2015 at 11:33 am #4937
tatamataMemberit did not work with an array as you suggested. tried it already
-
November 12, 2015 at 11:40 am #4939
tatamataMemberwhen i choose some values in select boxes and update the page1 and then go to page2, all values stay as i choose them on page1. if i change them on page2 and go back to page1e, values are as i choose them on page2. but still no trace of any meta recorded in the database
-
November 12, 2015 at 12:45 pm #4949
SteveKeymaster@tatamata— I’m not 100% sure what Page 1 and Page 2 mean. It might be better if you zip up your plugin or theme and email to us at [email protected]
-
November 16, 2015 at 4:17 am #4974
tatamataMemberHello @Sbruner, thanks for the attention. Do you thing this might be related to stuck at update issue I am experiencing?
-
November 16, 2015 at 3:50 pm #4980
SteveKeymasterThat would only effect legacy data, not new data.
Is this problem with both or one?
-
November 16, 2015 at 3:53 pm #4981
tatamataMemberWhat do you mean?
-
November 16, 2015 at 3:59 pm #4984
SteveKeymasterThe upgrade script upgrades old data. New data should save properly.
I suggest you start commenting out some parameters to see which is conflicting.
You may want to start with this version. It removes the group in a group, which you don’t need:
piklist('field', array( 'type' => 'select', 'field' => 'best_of_frontpage', 'description' => __('Order of Best of tours for frontpage display.', 'raftrek'), 'label' => __('Best of - on Frontpage', 'raftrek'), 'columns' => 12, 'add_more' => true, 'choices' => piklist($best_of_choices, array('post_id','post_name')) )); -
November 16, 2015 at 5:45 pm #4990
tatamataMemberthanks Steve,
nailed it.
i made a function to retrieve the posts and moved the code below to the function inside the plugin file$args = array( 'post_type' => 'tour', 'tax_query' => array( array( 'taxonomy' => 'traka_taxo', 'field' => 'slug', 'terms' => 'best-of', ), ), ); $best_of_choices = array(); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) : $query->the_post(); $best_of_choices[] = array("post_id" => get_the_ID(), "post_name" => get_the_title()); endwhile; wp_reset_postdata(); } else { _e( 'Sorry, no posts matched your criteria.' ); }but still it did not save.
then i decided to go back to the defaults, removing
'choices' => piklist($best_of_choices, array('post_id','post_name'))and use
'choices' => array( 'one' => 'one' ,'two' => 'two' )as you suggested but it still did not work.
to eliminate the last piece of code that stayed the same, the one retrieving IDs and titles of posts belonging to custom taxonomy, i used get_posts() instead WP_Query. at the end array structure stayed the same. only after completely removing WP_Query and wp_reset_postdata() from metabox and from plugin, saving meta started to work.
i hope this is valuable info to you.
thanks a lot for all your help and hard work on piklist support.
-
November 16, 2015 at 5:53 pm #4993
SteveKeymasterGreat. Glad it worked.
-
-
AuthorPosts
- You must be logged in to reply to this topic.