Can’t use get_the_terms after applying a pre_get_posts on a tax archive
Can’t use get_the_terms after applying a pre_get_posts on a tax archive
Can’t use get_the_terms after applying a pre_get_posts on a tax archive
The issue seems to arise because the pre_get_posts hook you’re using to filter media library queries might be affecting other queries as well, and your filtering condition isn’t targeting the exact query you’re trying to modify. Here’s a detailed breakdown and a solution: Key Points to Address: Scope the Query Correctly: Ensure your pre_get_posts filter … Read more
After posting the same question to multiple AI chatbots, CoPilot finally gave me an answer that works for both: add_action( ‘pre_get_posts’, ‘filter_files_admin_columns’ ); function filter_files_admin_columns( $query ) { if ( !is_admin() || ‘eri-files’ !== $query->get( ‘post_type’ ) ) { return; } add_filter( ‘posts_search’, ‘custom_search_query’, 10, 2 ); function custom_search_query( $search, $wp_query ) { global $wpdb; … Read more
I’m looking real hard at the code around both hooks, and they run one right after the other, with the same arguments, and I just can’t see any meaningful difference. Theoretically only parse_query would run, and not pre_get_posts, if WP_Query::parse_query() were to be run directly on its own, but WordPress itself never does that. Maybe … Read more
In order for sorting by a meta value to work, the meta_key parameter is required (source): Note that a meta_key=keyname must also be present in the query. Unfortunately this will result in only posts with the meta key set to be found by the query. From here there are two options: Use a query to … Read more
In order for sorting by a meta value to work, the meta_key parameter is required (source): Note that a meta_key=keyname must also be present in the query. Unfortunately this will result in only posts with the meta key set to be found by the query. From here there are two options: Use a query to … Read more
For the frontend, you can use template_redirect action to identify the page, and perform redirects or adjust the request on the fly (untested): add_action( ‘template_redirect’, static function () { if ( ! is_singular( ‘cpt’ ) && ! is_post_type_archive( ‘cpt’ ) ) { return; } if ( current_user_can( ‘read_private_pages’ ) || current_user_can( ‘read_private_posts’ ) ) { … Read more
How can meta values from another site in a multisite be used in a custom query?
Can I filter existing search query using pre_get_posts for post_mime_type?
For those who face the same issue, I post my solution that seems to work (I am keeping my fingers crossed that I still need to test to see if everything is running well). I found the solution thanks to this post I removed the pre_get_posts that made my life miserable. I put the tag.php … Read more