Custom Metabox Not Saving

When you do that include, you are trying to add the save_post hook inside the add_meta_boxes_$post_type hook. It should be independent. add_action( ‘add_meta_boxes_page’,’load_home_meta’ ); add_action( ‘save_post’, ‘save_home_meta’ ); // Declare all callback functions Also, you shouldn’t declare a function inside a function. Maybe you should consider creating a plugin for handling this, see: Where to … Read more

global function to apply filter to custom field

I have no experience with the get_{$meta_type}_metadata filter either, hence all I can offer is a further approach to a possible workaround: Iff you don’t need to satisfy third parties using get_post_meta, but only want to use the filter in your own code, you could write a custom wrapper for get_post_meta, which in turn will … Read more

Display custom field if it exists and has a specific value [closed]

You can hook into the_title() to alter the output. In functions.php paste this: function my_change_title( $title, $post_id ) { $custom_title = get_post_meta($post_id, ‘mycustomvalue’, true); if( isset($custom_title) && $custom_title == ‘apple’ ) return $custom_title; return $title; } add_filter(‘the_title’, ‘my_change_title’, 10, 2); In your template, you can just use <?php the_title(); ?> To use your custom value … Read more

Auto Populate Custom Field with Complex Value That Increase by One?

I suppose you need somewhere to globally store last order number. Preferable in table wp_options. Method update_option will help you. Then you need to make a function which will fires everytime when new order appears. something like that: add_action( ‘save_post’, ‘setOrderNumber’); function setOrderNumber($post_id) { $slug = ‘orders’; // slug of your post_type called “Orders” if … Read more

Users Select inside custom metabox

I think the problem is you are passing the WP_User_Query object, not the results of the query. Try to change: $fields = array( array( ‘id’ => $prefix . ‘user_sub’, ‘name’ => ‘Subscriber User’, ‘type’ => ‘select’, ‘use_ajax’ => false, ‘options’ => $user_query, // this is where you populate the select in metabox ), ); To: … Read more