Tag Info

Hot answers tagged

5

You should be able to do that with: /** * Setup a custom hook before the second post on the search page */ add_action( 'the_post', function( $post, \WP_Query $q ) { if( $q->is_search() && $q->is_main_query() && 2 === $q->current_post ) { do_action( 'wpse_before_second_post_in_search' ); } }, 10, 2 ); /** * ...


3

The problem with your approach is that woocommerces product category is a custom taxonomy called product_cat. But with cat you are addressing the built-in category. Taxonomies can be addressed with a tax query, simplified example below: function wpse188669_pre_get_posts( $query ) { if ( ! is_admin() && ...


2

You can use the pre_get_posts hook. Do note though, this hook filters the query on both the front-end and admin. For example, we could do something like this: function search_post_types( $query ) { if( is_admin() ) { return $query; } if ( $query->is_search && $query->is_main_query() ) { $query->set( 'post_type', ...


1

On a stock WordPress installation, WP_Query will default to post_type = 'post'. Consider this simple example: $args = array( "posts_per_page"=>5, "ignore_sticky_posts"=>true ); $itposts = new WP_Query( $args ); It will result in the following query to be executed: SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND ...


1

If you check the documentation for WP_Query you will notice that post_count, which you are using, returns the number of posts being displayed. That is what you see, but not what you want. found_posts returns the total number of results for the query, which is what you want. $post_count The number of posts being displayed. $found_posts ...


1

I have some recommendations for your question: First: stop using query_posts(). See the codex about this function to see why you shouldn't use it in themes or plugins. Anyway, if you are in a some weird situation where you have not option and you need to use query_posts(), you should run wp_reset_query() after the loop. You must know that you are using the ...


1

This is not how pre_get_posts works. The pre_get_posts action gives developers access to the $query object by reference (any changes you make to $query are made directly to the original object - no return value is necessary). https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts What you are doing is simply wrong. You don't ...


1

Try this and change the classes if needed. <div id="navbar" class="navbar"> <nav id="site-navigation" class="navigation main-navigation" role="navigation"> <button class="menu-toggle"><?php _e( 'Menu', 'twentythirteen' ); ?></button> <a class="screen-reader-text skip-link" href="#content" title="<?php ...



Only top voted, non community-wiki answers of a minimum length are eligible