Using pre_get_posts to filter by custom fields while using static front page
Using pre_get_posts to filter by custom fields while using static front page
Using pre_get_posts to filter by custom fields while using static front page
I think I remember seeing this attempt somewhere… If I remember correctly, the solution was to use a custom tax query on the category.php template, but querying the taxonomy (crosspostcategory) FIRST in the “or” statement… So you’d check for the taxonomy first, and then query (tax query) the category taxonomy next in the OR statement. … Read more
custom post types, pre_get_posts, wp_list_categories
I’m outlining a solution for what you asked in your last comment, because this wouldn’t been fitting for the comment format. Code: function date_time_to_timestamp_meta( $post_id ) { // meta fields are saved in DATETIME, e.g. »2013-12-09 22:32:12« // here is only the date part relevant $datetime_date = get_post_meta( $post_id, ‘_start_date’, true ); // here is … Read more
query_posts() should not be used in general and especially when dealing with pagination. You need to be making adjustments before template is reached, usually via pre-get-posts hook, on which there is plenty of material on site.
why is pre_get_posts not working
There is nothing wrong with that code. It’s correct and working fine for me on a default installation. Change to using the default theme. Does it work now? If so, then there’s something wrong with your theme. Disable other irrelevant plugins. Does it work now? If so, then one of those plugins was interfering. Eliminate … Read more
Based on my subsequent review of wp-includes/query.php, what I was attempting is simply not possible. This is because the query vars may only be modified to predefined set of values. As best I can determine, you cannot arbitrarily modify queries.
Your SQL dump proved to be informative.. Either 1=2 or 1=0 in a SQL statement means something you passed your WP_Query was invalid. It appears that in your tax_query you specified ‘field’=>’term_id’, which isn’t a valid option – it should be just ‘field’=>’id’.
Rather than using pre_get_posts hook, you could try a better approach which will work perfectly with parse_request hook. The code – add_action( ‘parse_request’, ‘my_cpt_parse_request’, 11, 2 ); function my_cpt_parse_request( $wp ) { if( isset($wp->request) && !is_admin() ) { $requests = explode(“https://wordpress.stackexchange.com/”, $wp->request); $request_amount = count($requests); $post_name = array_shift( $requests ); // if an attachment has … Read more