How to return Meta data from the REST API?

The first parameter passed to register_meta() is always post for posts, Pages (post type of page) and custom post types. However, the REST API Handbook says that: Prior WordPress 4.9.8, meta fields set to show_in_rest using register_meta are registered for all objects of a given type. If one custom post type shows a meta field, … Read more

Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)

To me, the simplest solution would be creating additional field in JSON response and populating it with selected post meta: function create_api_posts_meta_field() { // “tribe_venue” is your post type name, // “protected-fields” is a name for new JSON field register_rest_field( ‘tribe_venue’, ‘protected-fields’, [ ‘get_callback’ => ‘get_post_meta_for_api’, ‘schema’ => null, ] ); } add_action( ‘rest_api_init’, ‘create_api_posts_meta_field’ … Read more

How to filter custom posts by tags and custom fields?

you can use custom taxonomies and make you query_posts much easier! by that i mean create a custom taxonomy for type,duration like so: add_action(‘init’,’register_event_tax’); function register_event_tax(){ register_taxonomy(‘even_type’,array(‘events’), array( ‘hierarchical’ => false, ‘labels’ => ‘type’, ‘show_ui’ => true, ‘query_var’ => true, ‘rewrite’ => array( ‘slug’ => ‘type’ ), )); register_taxonomy(‘even_duration’,array(‘events’), array( ‘hierarchical’ => false, ‘labels’ => … Read more

How set featured posts using checkbox in post edit screen?

You can do this by following these steps: Add a custom meta box to your posts Create a function to save the meta data using the save_post action Add the ‘meta_key’ query argument to whatever query you are using. Place this in your themes functions.php file: function register_post_assets(){ add_meta_box(‘featured-post’, __(‘Featured Post’), ‘add_featured_meta_box’, ‘post’, ‘advanced’, ‘high’); … Read more

How to correctly call custom field dates into a posts_where filter using SQL statements

Thanks to AmbitiousAmoeba for the answer. The following improved code solves the problem: function filter_where( $where=”” ) { global $wpdb; $where .= ” AND (($wpdb->postmeta.meta_key = ‘original_date’ AND $wpdb->postmeta.meta_value >= ‘2000-01-01’) AND ($wpdb->postmeta.meta_key = ‘original_date’ AND $wpdb->postmeta.meta_value <= ‘2004-12-31’)) “; return where; } add_filter(‘posts_where’, ‘filter_where’); query_posts($query_string); while (have_posts()) : the_post(); the_content(); endwhile;

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)