WP_Query not using relation key as expected and not producing any results

From the developer docs: relation (string) – The logical relationship between each inner meta_query array when there is more than one. Possible values are ‘AND’, ‘OR’. Do not use with a single inner meta_query array. (Emphasis mine). It’s a bit hacky, but you could run a separate query against the meta field, then merge the … Read more

Custom Post Types Do Not work on this permalink setting https://somedominaname.com/%category%/%postname%/

The Permalink structure setting on the Permalink Settings admin page is only applied to the default post type, i.e. post. For custom post types (CPTs), you can set the permalink structure (for posts in your CPT) when registering your CPT, via the rewrite argument for register_post_type(). But, if you want to use %category%/%postname% with your … Read more

Can Multisite and Custom Post Types work this way?

You can put something like this in a theme template: <?php switch ( get_current_blog_id() ) { case 9: $category = ‘alignment’; break; case 13: $category = ‘lists’; break; case 14: $category = ‘comments’; break; default: $category = ”; break; } switch_to_blog( BLOG_ID_CURRENT_SITE ); // root site. $category_posts = get_posts( array( ‘category_name’ => $category, ) ); … Read more

How to work with URLs where sometimes a post or a subcategory is in the same part of the URL structure

Your challenge lies in the way WordPress interprets URL patterns and resolves them to query variables. When you have a URL structure where the third segment can be either a subcategory or a product name, WordPress struggles to differentiate between the two. This is a common issue in WordPress when using custom post types and … Read more

How to check if a custom post type uses a custom template?

I mean “Full Width” like we do with pages : is_page_template( ‘Full Width’ ) ? is_page_template() does not accept a Template Name value like Full Width, but instead, a file name such as full-width.php or templates/full-width.php. Secondly, is_page_template() can be used with any post types and not just Pages (page post type), so you can … Read more