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
- getEntityRecords/useEntityRecords: How to use CPT metadata?
- Ignoring slug capitalization on rewrite rule for custom post type archive page
- Importing Data from a Non-WordPress database, into WP
- Getting thumbnails of a custom posts featured images in a page-templates metabox
- filter search custom field query
- List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
- Remove Post Custom Meta Box
- How to let users choose where to search for posts?
- Paginate_links in custom post type template
- Query based on custom fields start and end date
- Can’t publish custom post type – “You are not allowed to edit this post.”
- Custom fields for custom post type
- Show future events based on custom field AND order by date
- My archive-posttype.php template is not loading
- Custom Post Archive is not working
- Meta Data for Custom Post Type not saving
- Using preg_replace to filter custom textarea
- Limit the Title Length on Custom Post Type Archive Page to a Set Number of Characters
- Custom post type archive with page as parent url
- Add parent post to Custom Post Type [closed]
- Set featured image to archive.php
- Check if post with same meta value exists
- Filter date from post meta when date is in string format
- Get only used meta_values
- If Post Meta Equals Current Title Conditional Advanced Custom Fields
- Is there a way to exclude posts based on meta_values?
- What’s the name of the custom post type yearly archive template?
- Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
- Custom post type, global categories — what’s the template name?
- Archieve.php not loading for custom post type
- How to hyperlink content from archive page with custom post-type
- Submitting Custom Post Types with custom fields from Front-end form
- Set thumbnail and title for a post type archive (not post itself!)
- create custom meta box with default value
- How to set up Custom Post Type archive page as Front page
- Url to archive page for custom post type
- How can I use archive-{post_type}.php theme template?
- Get $post->ID from a URL
- How to display CPT archives?
- Displaying a div from an assigned meta_value when on a page
- Custom meta Title for custom post type archive from page
- Meta data (Tags and Categories) for Custom Posts not showing.
- Display different information of a custom post type
- Excluding a Custom Post Type with a specific tag using pre_get_posts
- WP_query – Filter by tax_query and meta_query using multiple select
- Create Array from custom post type to display a slider
- Setting Post Title via Meta Data returns Auto-draft
- Return the name of the post type
- Is it possible to load a different sidebar in single.php based on a meta_query filter?
- How to Echo Metadata Value in Currency Format
- Issue on Working with Metabox – Checkbox to enable Sale Items
- Filter posts by tax (dropdown) and meta value
- delete_post_meta() for whole CPT / multiple posts?
- How to get specific post meta by title or id
- Publish and save specific postmeta to a filtered post_type
- 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?
- Getting a custom post’s custom field based on another custom post’s custom field select
- Why do I have to press the “Update” button twice to save my meta box values?
- Alphabetically sort a taxonomy.php template by post title
- Querying multiple values from a single key
- How can I display a drop-down select of Post Names
- how to show records that don’t have custom meta value
- Custom Permalinks For CPT and pages with parent. Advanced WordPress
- How to integrate single and archive templates for custom post type in any WordPress theme
- Permalink problems with custom post type and custom taxonomy
- WP API Response does not show my registered metadata
- sort CPT on Custom Taxonomy Archive page
- How to detect that the save_post hook is calling the callback associated to the current edit post page only
- find custom post type post by searching its custom field with my string
- $post->post_meta not pulling any post in wordpress/php
- Values from meta-box not on $_POST
- Get category if used in a custom post type
- ACF for custom post type archive pages: which hook to use?
- Returning a custom content types with meta values
- Use the custom post type archive for taxonomies?
- Custom post type suddenly stoped working after WordPress 5 update
- Batch Extract Date from post title and put into ACF custom field
- copy images from custom field to another custom field
- Custom Query: If One Post Object Field Value Is The Same As Another
- Query for post and costom post_type in same category filtered by meta for post_type
- If meta_value of meta_key is less than today’s date update meta key