Tag Info

Hot answers tagged

4

Is this possible via query args? I don't think so. Is this possible via 'posts_where'? It is probably doable using some 'posts_*' filters, not only with 'posts_where'. Or maybe using 'posts_request' filter to completely oveeride the query. Do I need to run a separate query and then somehow merge the results? That would be the simplest ...


4

Here is another approach with pre_get_posts. Use get_posts() ( x2 queries ) to get all the post ids of each post type according to its requirements. Add the fields parameter ('fields' => 'ids') to your query arguments to just fetch post ids as this is what we need, nothing else. This will drastically improve performance and will not be that tough on ...


2

You can use pre_get_posts to modify the main query, but you will need to create new queries for the other searches. Use get_query_var('s') to get the search terms and create new WP_Query objects to perform your search. Without more information it is hard to provide much more detail to the answer.


2

As already mentioned, don't use query_posts(). Even the WordPress docs state this: Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new ...


1

The WP_Query documentation on the codex specifically says: 'attachment' - an attachment. Whilst the default WP_Query post_status is 'publish', attachments have a default post_status of 'inherit'. This means no attachments will be returned unless you also explicitly set post_status to 'inherit' or 'any'. I am not sure why it was working before ...


1

This is what I changed it to, and it seems to be working on the Homepage without extra added code. <ul class="brands"> <?php global $post; $posts = get_posts( array( 'numberposts' => 99, 'post_type' => 'brands', 'order' => 'ASC' ) ); if( $posts ): foreach( $posts as $post ) : setup_postdata($post); ?> ...



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