How to exclude posts by ID within a category/archive loop

Use pre_get_posts to exclude the categories you don’t want to display in the loop. function exclude_posts_from_specific_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘cat’, ‘-2’ ); } } add_action( ‘pre_get_posts’, ‘exclude_posts_from_specific_category’ ); Or create a new WP_Query and use the Category Parameters. $args = array( ‘category__not_in’ => 2 , ‘category__in’ => … Read more

WordPress tax_query ignoring relation OR

I’ve came up with the not perfect solution to this: Because I am using term_taxonomy_id I can just add all the IDS and remove the taxonomy specification like this: ‘tax_query’ => array( array( ‘field’ => ‘term_taxonomy_id’, ‘terms’ => array(…all ids…) ) ) And it works! This is a quick solution, although it will work in … Read more

Pagination not working in custom loop WP_Query

Having same problem. Ended up with the following codes global $woocommerce_loop; $woocommerce_loop[‘paged’] = (isset($woocommerce_loop[‘paged’])) ? $woocommerce_loop[‘paged’] : 1; $woocommerce_loop[‘total’] = $custom_query->found_posts; $woocommerce_loop[‘post_count’] = $custom_query->post_count; $woocommerce_loop[‘per_page’] = $per_page; $woocommerce_loop[‘total_pages’] = ceil($custom_query->found_posts/$per_page); $woocommerce_loop[‘current_page’] = $args[‘paged’];

pages shortcode filtering by category

ob_start() This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. ob_get_clean() Gets the current buffer contents and delete current output buffer. try this code function qut_research_subpages_shortcode_frontend($atts) { $args = array( ‘post_type’ => ‘page’, … Read more

Change archive results based on GET request

You have multiple ways to make this work. What you can do for example, target a page and in the theme for this page or better say the template go and read the GET and make the filtering there. Another approach and what I personally do is create a page and then start playing with … Read more

why ignore_sticky_posts in sticky post query

We all know that ignore_sticky_posts is used to exclude sticky post from your custom query. – No, this assumption is wrong. What ignore_sticky_posts means: Even though in natural English, ignore_sticky_posts sounds like WordPress should ignore all sticky posts from the query, in reality that is not what WordPress does. Instead, you should read ‘ignore_sticky_posts’ => … Read more

How to create URL parameters to run custom queries?

What you want to do is access the query_vars and use them. Base code: Page to access the fields $custom_field = get_query_var(‘custom_field’); var_dump($custom_field); And the function or custom plugin to save the magic: add_filter( ‘query_vars’, ‘my_custom_query_vars’ ); function my_custom_query_vars( $vars ) { $vars[] = ‘custom_field’; $vars[] = ‘custom_awesome_field’; return $vars; } yourawesomesite.awesome/?custom_field=white string ‘white’ (length=5)