You got it pretty close. Here’s a working example of what you’re trying to do:
class Wpse_126374 {
public function __construct() {
add_action( 'init', array( $this, 'rewrites' ) );
add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
}
public function rewrites() {
add_rewrite_tag( '%parent_id%', '(\d+)' );
}
public function pre_get_posts( $query ) {
// Don't run this on admin pages or secondary queries
if ( is_admin() || ! $query->is_main_query() || $query->is_archive() )
return;
if ( '' != ( $parent_id = get_query_var( 'parent_id' ) ) ) {
$query->set( 'meta_key', '_wpcf_belongs_artist_id' );
$query->set( 'meta_value', $parent_id );
}
}
}
$wpse_126374 = new Wpse_126374;
This should allow you to have parent_id=24
in the URL.
Related Posts:
- Display custom post type and custom fields within a Bootstrap Carousel
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- WP insert post PHP function dynamically generated Custom Fields
- Having trouble with custom date field for CPT query (WordPress)
- Sort posts based on multiple custom fields
- Conditional to modify query results
- query posts and custom post type with meta key
- Querying Two Custom Post Types with OR Not Working
- First custom field value (out of several) displayed twice after query
- It’s possible to hide body copy box for a custom post type?
- How to conditionally add Custom Post Type to Front Page
- Display a post from custom post type only if all the selected taxonomies and custom field value matches the record
- Custom Query: If One Post Object Field Value Is The Same As Another
- Filtering custom posts by custom fields (ACF) [closed]
- WP Query from two Custom Post type fields as statement
- Using OR relation in meta_query to check for a value before sorting by another
- Meta query and compare “!=” not working as expected
- How do I query with multiple custom fields orderby in same column?
- How do I display specific custom posts, and how do I edit a post’s singular page?
- Show first posts with custom field not empty and order all by title
- Filter CPT based on meta box value using Flexible Posts widget?
- How to grab data (titles, thumbnails and custom fields) from multiple posts to populate a new array efficiently?
- Filter Custom post type by another Custom post type
- Get Posts ordered by a date custom meta field
- ACF From & To Date Validations
- How do I set all of a particular post meta to a value within the custom post type I’m in?
- Query Multiple Custom Posts by Custom Fields
- Show image gallery from a custom field
- Specific query for custom post type
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- Dynamic dropdown select values depending on other custom field value
- How to render a custom post type template with custom fields using shortcode
- Disable saving posts as draft (make all posts mandatory regardless of the post status)
- Grouping metadatas into one
- Tracking changes in admin-page so user gets warning when leaving the page
- filter custom post in rest api with custom function
- Get Posts by multiple custom fields is not working
- Woocommerce custom field search in custom post type [closed]
- Add custom field in comments form
- Custom Fields for Custom Post [closed]
- Order Custom Post Type by Custom Field Value
- Taxonomies relations
- Filter custom post types by a field value
- Displaying All Posts of a Custom Post Type in WordPress Multisite Backend
- Repeatable Fields Metabox with Textarea (or wp_editor)
- How to use TinyMCE Editor for one of my custom post meta field?
- Custom REST endpoints for a custom post type with custom fields
- How to Create a WordPress Plugin With Custom Post Type/Custom Field Features?
- Display post content with respect to its title?
- Hierarchy and access control for Custom Post Types (CPT)
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- How to integrate a form (Ninja Form or Contact Form 7) with Custom Post Types?
- Prioritize posts in query by meta keys?
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Meta Query posts not showing on ending date of custom field
- Cannot save CPT meta box
- Cross reference custom post types
- Adding Page Templates to post but it ignored it
- What’s the equivalent of Hide From Menus on MODX on WordPress?
- Include related custom fields from one post type in another post type’s JSON feed
- Admin Custom Meta Box – Pull Last 5 Posts from Custom Post Type
- frontend image post uploader
- WP_Query orderby and tax_query
- Is there any way to add a “custom field” to the CPT archive page?
- I am trying to hide a custom post type category to logged in users with Pre_Get_Posts
- Displaying Posts from Custom Post Types
- Different Ways to Query Custom Post Types?
- How to Output which matched meta_keys were found from custom_type_posts?
- Multiple Frontend Filters Using Advanced Custom Fields
- Custom Post Fields at the beginning of a Custom Permalink
- Integrate Custom Post Type Events into Calendar
- Possible to filter custom post type with multiple meta data?
- Hierarchical custom fields
- How to get a custom field value of a custom post?
- Fields for different parts of a page
- Is it possible to activate customfield ‘text description’ upon activating the customfield ‘checkbox’?
- Facebook social publisher and custom post type fields [closed]
- How to display products name in a non-alphabetical order, in a custom field (taxonomy)?
- Displaying custom field according to date
- Displaying and searching Custom Posts
- Importing Data from a Non-WordPress database, into WP
- custom comments form for custom post type
- Searching Custom Fields
- How to organise this data within WordPress
- Show fields based on taxonomy selection in editor
- filter search custom field query
- Permalinks: custom structure for taxonomy – tags?
- How can I list Custom Post Types created with the Types plugin under categories?
- How to let users choose where to search for posts?
- don’t publish custom post type post if a meta data field isn’t valid
- WebP Fallback for Inline Background Image in Style Attribute
- Query based on custom fields start and end date
- How to add multiple markers on the google map, at a certain meta_key and meta_value
- Custom post type posts don’t show in archive widget
- Custom fields for custom post type
- How can meta boxes be added to “unknown” custom posts?
- Custom “radio button meta box” not saving correctly
- Showing specific post in order of array wp_query
- Can we create a custom post template for a specific page template