I agree with the comments to the question that there is probably a better way to associate your post types, however, the question is interesting in a “code golf” sort of way 🙂
I now need to query the database to find out if an Episode has a
particular type of Snippet associated with it. This SHOULD be easy if
‘page_title’ was a valid entry in $args but it seems that it isn’t.
(It took me a sizeable chunk of today to realise that!)
name
and pagename
both address the slug
but not with a wildcard, as you can see if you try this:
$args = array(
'post_type' => 'book',
'name' => 'test',
);
$q = new WP_Query($args);
var_dump($q->request);
The easiest way to accomplish that wildcard trick is with a filter on posts_where
:
function wildcard_post_slug($where) {
remove_filter('posts_where','wildcard_post_slug');
global $wpdb;
return $where.' AND '.$wpdb->posts.'.post_name LIKE "Episode_%"';
}
add_filter('posts_where','wildcard_post_slug');
$args = array(
'post_type' => 'book',
);
$q = new WP_Query($args);
var_dump($q->request);