Support

Account

Home Forums Backend Issues (wp-admin) Sorting a column for a user field Reply To: Sorting a column for a user field

  • Another bit of code to go with the previous one that updates all previously created posts of type my_custom_post_type with the extra meta data instead of having to manually do it.

    /**
     * Update post meta for sortable column
     */
    if (is_admin() && isset($_GET['addsortablemeta']) && $_GET['addsortablemeta'] == 1) {
    	$args = array(
    		'post_type' => 'my_custom_post_type',
    		'nopaging' => true,
    	);
    	$my_query = null;
    	$my_query = new WP_Query($args);
    	if ($my_query->have_posts()) {
    		while ($my_query->have_posts()) : $my_query->the_post();
    			my_acf_save_post($post->ID);
    		endwhile;
    	}
    	wp_reset_query();
    }