That’s because ‘meta_key’ and ‘meta_value’ are not public query vars. In other words, you can’t use them in URLs directly, nor should you.
Instead, register a specific query var, like so:
function register_my_qv() {
global $wp;
$wp->add_query_var( 'my_qv' );
}
add_action( 'init', 'register_my_qv' );
Then, you can go to a URL like this: ?my_qv=foobar
All you need to do now is map your query var to the actual query you want to do:
function map_my_qv( $wp_query ) {
if ( $meta_value = $wp_query->get( 'my_qv' ) ) {
$wp_query->set( 'meta_key', 'some_meta_key' );
$wp_query->set( 'meta_value', $meta_value );
}
}
add_action( 'parse_query', 'map_my_qv' );
Related Posts:
- Ordering posts having multiple post-meta date fields
- Custom Queries: Joining On Meta Values From Two Custom Post Types
- How Can I save multiple records in same meta key?
- Compare 3 custom fields and sort by oldest
- Can’t sort order of wp_query with 2 meta keys
- Custom query variable – get wordpress to redirect to nice permalink url
- Displaying Metabox value (custom post type taxonomy)
- Get posts between custom dates
- WP_Query of custom post type sorted by meta_key has unexpected results
- WP_Meta_Query object with conditionals
- Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
- Use WP_query to match post types based on custom field values
- Show posts from WP Custom Post Type selected from a field in a metabox
- Creating an archive page or simple template to list all values of a custom field of specific post type listing
- Meta_query by date for Events archive
- meta query always fails even if data is correct
- Querying meta values within an array
- Check for custom field value in different post type than current one and do something
- Get posts based on meta key/value
- How to create a wp_query that contains both meta_query and tax_query
- Proper way of making custom post type landing page or archive page
- Custom Post Type Archives with 0 Posts Redirects as 404
- Order Posts by Taxonomy and Meta Value
- How to get_queried_object on multiple objects?
- Assign Page Template Within A Custom Post Type
- Grossly inefficient wordpress loops!
- How Do I Use WP_Query to Run This Database Query as Search Result?
- paginate function in archive for custom-post-type
- Should I change these content meta types before building complex archive page?
- Custom post type category not displaying in custom post type
- exclude custom post type by meta key in wp_query
- How to create archive page for taxonomy terms within custom post type
- How to add multiple featured image in meta box in post editor?
- How to list custom post types?
- How to best delete orphan wp_postmeta
- Display only post types that are direct children of the current taxonomy
- Custom post type search with slug in URL
- Count posts with specific term_meta
- Custom search for custom post meta with pre_get_posts interferes with WP search
- How can I give CPT archive correct body class?
- Is it possible to apply a meta_query to one specific post type in a query with multilple post types?
- WordPress Orderby Numeric Value Not Working
- Replace title column in post list with post meta value
- Ordering posts in Search & taxonomy by post_meta
- Custom post type is showing custom home page, not archive page
- URL of a custom post type’s post format archive?
- How to use has_archive but disable feed per post type?
- Restrict Access to Posts based on Custom User and Post Meta Data
- Why is this query not working? (Standard posts + custom post type)
- Custom Post Type has_archive
- list archives per post types
- Is it possible to have a custom post type with feed but without the archive?
- Add parent post to Custom Post Type [closed]
- What’s the name of the custom post type yearly archive template?
- create custom meta box with default value
- How to display CPT archives?
- current-menu-item not added on page showing custom post type (rendered with archive template)
- How to move a post to different post type with all meta data?
- Why do I have to press the “Update” button twice to save my meta box values?
- Permalink problems with custom post type and custom taxonomy
- WP API Response does not show my registered metadata
- How to detect that the save_post hook is calling the callback associated to the current edit post page only
- Use the custom post type archive for taxonomies?
- Query for post and costom post_type in same category filtered by meta for post_type
- fetch custom post by meta key if key value is does not know
- Problem with adding custom post type meta to header by plugin
- Echo custom post meta from options array
- Value of post meta dropdown is not showing in WordPress
- Trying to write shortcode with get_post_meta but isn’t working
- updating one custom meta field only
- Custom post type category permalinks and archive pages
- How to order query results based on if a custom field has been populated, then the order by the date of the post?
- CPT archive with WP native/core tax/categories
- Should I use a custom taxonomy or custom post type for grouping a list of panels associated with a group of tests?
- How to add specific terms in a custom post type?
- Peepso: Add extra data field (custom post meta) to postbox
- meta query multiple values for the same key
- Change picture attachment meta of all occurrences of a picture
- Unknown Post Meta Records
- Get Previous Post based on Custom Field Name, for Custom Post Type
- Custom post types – meta_query: search lesson which starts sooner
- Saving custom post types post_meta over REST-API fails
- How to manage a custom post type archive as a page?
- Stripe multiple transactions
- Custom post types not displaying per category
- Querying, storing, and using data from 2 separate custom post types
- Custom post type with two templates
- Edit is changing my custom’s post type parent id
- Edit post meta direct from post.php?
- Timetable of Custom Meta Data using Custom Post Type and Custom Taxonomy
- Custom post type category page not working
- Change the contents of a dropdown through the admin panel?
- CPT Archive with parent page
- loop through custom post-type with two meta_keys
- fetch meta fields inside a widget
- Custom post type – update_meta not working
- Remove plugin’s custom post type archive page and single pages [closed]
- Use a Variable in update_post_meta as the $meta_key
- add_filter > posts_where works partially
- Meta_query question