Custom Post type in Author.php

You need to pass the post types as an array, not each as its own argument. $q->set( ‘post_type’, [‘design’, ‘accessory’]); // ^ ^ Or if you’re on older PHP systems $q->set( ‘post_type’, array(‘design’, ‘accessory’));

Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far

Using the Query Monitor suggested by @Andrew (Thanks, Andrew!) I found a little gem in my parent theme that overrides everything set in my function. I found out wordpress loads the child themes functions.php first myfunction{ $query->set( ‘posts_per_page’, 15 ); } so when it later loaded lameparentfunction{ $query->set( ‘posts_per_page’, 5 ); } It undid the … Read more

I did group my search results by post type, but how can i give each of them its own order?

Here’s one suggested high level approach to get the desired effect. Rather than perform all your operations in one big while loop in your searchresults.php, try: establishing three arrays corresponding to each type- you can do this in one while loop. then sort each array as needed (refer to PHP’s Sorting Arrays documentation for the … Read more

Relative URLs for a particular custom post type?

At @milo’s suggestion, I used the post_type_link example and adapted it to my needs. This made it so only my chosen post type would be relative, while leaving any other custom post types functioning as usual. function make_yourposttype_relative ( $url, $post ) { if ( ‘yourposttype’ == get_post_type( $post ) ) { add_filter( ‘post_type_link’, ‘wp_make_link_relative’ … Read more

get_object_taxonomies() returns empty array for custom post type

I have run into the same issue. I believe the root cause is the order of execution. For the sake of experiment, I ran get_object_taxonomies() immediately after register_taxonomy(), in fact in the same function and it worked as expected. So what to do? Use add_action() hook to execute get_object_taxonomies() after register_taxonomy(). The correct order of … Read more

Custom taxonomy in custom post RSS feed

You can hook into the request filter and set the post types to whatever you wish: add_filter( ‘request’, ‘cpt_in_rss’ ); function cpt_in_rss( $request ) { if ( isset( $request[‘feed’] ) && ! isset( $request[‘post_type’] ) ) { $request[‘post_type’] = [ ‘post’, ‘cpt1’, ‘cpt2′ ]; } return $request; } Here’s a trac ticket about what you … Read more

WP_Query: include custom post type only with specific meta value

If the key-2 is uniquely assigned to cpt-3 post type, then you can add another meta query argument to your query arguments: array( ‘key’ => ‘key-2’, ‘value’ => 1, ‘compare’ => ‘=’ ) If not, you can run another query, and then merge them as follows: $final_query = array_merge( (array) $query_1, (array) $query_2 ); But, … Read more