Viewing 11 reply threads
  • Author
    Posts
    • #4925
      tatamata
      Member

      Hi,

      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.

    • #4926
      tatamata
      Member

      using piklist 0.9.9.6

      other metaboxes tied to custom post type save normaly.

    • #4936
      Steve
      Keymaster

      @tatamata– If you change the choices array to something like this:

      'choices' => array(
      'one' => 'one'
      ,'two' => 'two'
      )
      

      Does it work?

      If so, then you are not constructing your array properly.

    • #4937
      tatamata
      Member

      it did not work with an array as you suggested. tried it already

    • #4939
      tatamata
      Member

      when 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

    • #4949
      Steve
      Keymaster

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

      • #4975
        tatamata
        Member

        Page 1 means i.e. I am editing “about us” page, and page 2 means I am editing “contact” page.

    • #4974
      tatamata
      Member

      Hello @Sbruner, thanks for the attention. Do you thing this might be related to stuck at update issue I am experiencing?

    • #4980
      Steve
      Keymaster

      That would only effect legacy data, not new data.

      Is this problem with both or one?

    • #4981
      tatamata
      Member

      What do you mean?

    • #4984
      Steve
      Keymaster

      The 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'))
      ));
      
    • #4990
      tatamata
      Member

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

    • #4993
      Steve
      Keymaster

      Great. Glad it worked.

Viewing 11 reply threads
  • You must be logged in to reply to this topic.