Why am I getting an infinite loop with have_posts?
Look at this answer: get custom post type by tag I believe you’d use $flagged_stores->the_post() inside while loop.
Look at this answer: get custom post type by tag I believe you’d use $flagged_stores->the_post() inside while loop.
With this code you can search in post list in WordPress Admin Panel with custom post meta values along with title and other default fields. Please, add below code in functions.php file: if (!function_exists(‘extend_admin_search’)) { add_action(‘admin_init’, ‘extend_admin_search’); /** * hook the posts search if we’re on the admin page for our type */ function extend_admin_search() … Read more
I think I would write a wrapper function around custom fields, something like this: function get_post_transient( $post_ID, $meta_key, $update_function ) { $current_value = get_post_meta( $post_ID, $meta_key, true ); if ( is_array( $current_value ) && $current_value[‘expiration’] < date(‘U’) ) return $current_value[‘data’]; $new_value = call_user_function( $update_function, $post_ID ); update_post_meta( $post_ID, $meta_key, $new_value ); return $new_value[‘data’]; } and … Read more
Well, perhaps the answer could not be found in the WP_Query class for what I was trying to accomplish. Below is the final code that I plugged in to my functions.php file. I ultimately ended up search the WP_Query Class found in the wp_includes/query.php file. What I discovered is that there are a number of … Read more
All post meta is shown in the custom fields, unless it begins with an underscore. So to ‘remove’ post meta from the custom fields metabox, you simply have to give it a name, beginning with an underscore. You’ll then be responsible for saving/updating the post meta (adding your own metabox where necessary).
You should use some of WordPress’s built in functions, there is even a new meta compare parameter. You can create, for example: $state = get_post_meta($post->ID, ‘meta_state’, true); //the meta value to compare $query = new WP_Query ( array( ‘meta_key’ => ‘project’, ‘meta_value’ => ‘$state’, ‘meta_compare’ => ‘<=’, ‘post_type’ => ‘projects’ ) ); //spit them out … Read more
You can remove some of the header stuff with the following. // remove unncessary header info function remove_header_info() { remove_action(‘wp_head’, ‘rsd_link’); remove_action(‘wp_head’, ‘wlwmanifest_link’); remove_action(‘wp_head’, ‘wp_generator’); remove_action(‘wp_head’, ‘start_post_rel_link’); remove_action(‘wp_head’, ‘index_rel_link’); remove_action(‘wp_head’, ‘adjacent_posts_rel_link’); } add_action(‘init’, ‘remove_header_info’); The default installation does not include stuff like meta keywords, so that is either a theme or plugin that you are … Read more
Try this inside save_post but please note the code is not tested $old = get_post_meta($post_id, ‘products’); $new = isset ( $_POST[‘products’] ) ? $_POST[‘products’] : array(); if ( empty ($new) ) { // no products selected: completely delete alla meta values for the post delete_post_meta($post_id, ‘products’); } else { $already = array(); if ( ! … Read more
Slight change in your code, function wpse_custom_field_on_publish( $new, $old, $post ) { // Only run on “from X > to publish”-transitions if ( $new === ‘publish’ && $old !== ‘publish’) { $page_views = get_post_meta( $post->ID, ‘post_views_count’, true ); // Only set ‘post_views_count’ post meta value if there is none so far if ( empty( $page_views … Read more
Here is what I have learned about the WP REST API: It is a mess of undocumented and unfinished code with great promise but frustratingly little clarity. That said, I have a workaround that I will post here, hoping it is useful to others in a similar pickle to me: I just found that I … Read more