Articles of wp query

Minimize database queries to user tables?

I’m trying to come up with a strategic way to collect large amounts of usermeta data (and output to the screen) while keeping database queries low. Some pages, like the home page, single pages, and category pages, load up in less than half a second with 40-60 queries. Other pages that contain large amounts of […]

Query: offset post list, unless it's a specific category

Here’s my code: <?php query_posts(array (‘showposts’ => ‘1’, ‘cat’ => ‘-11’)); if (have_posts()) : while (have_posts()) : the_post(); get_template_part( ‘content’, ‘archives’ ); endwhile; endif; ?> <?php query_posts(array (‘showposts’ => ‘3’, ‘offset’ => ‘1’)); if (have_posts()) : while (have_posts()) : the_post(); get_template_part( ‘content’, ‘archives’ ); endwhile; endif; ?> The first query excludes a category (user contributions […]

Storing query variable and then using wp_reset_query

I want to use a pagination function with a custom posts query (to get posts from a specific category). My pagination function gets the query from global $wp_query; So in the following code I have assigned the original $wp_query to a temporary variable and after the query I assigned back. Finally I used wp_reset_query() function […]

How to query for posts without a post_format

I have looked in the WP codex for an example which shows how to use a taxonomy query to retrieve a set of posts that have no post_format. IOW: ‘All posts where an aside or quote or link…etc… post_format has not been assigned; eg. a ‘standard’ post_format.’ But I can’t seem to figure out how […]

Search – Ajax – Alter Query Parameters with Pagination

Too Long ; Didn’t Read How do I get pagination to work when I’m creating my query with ajax? I’m working on creating a functional search page that allows the user to filter how many posts per page. I don’t quite understand how to create it so pagination functions correctly and was hoping somebody could […]

Display multiple custom post types and sort them chronological by one of their fields

I have four custom post types created with the custom post types ui plugin; each stands for an event type with a different set of custom fields created with the advanced custom fields plugin. My goal is to show all events out of the pool of the four chronological. To query the four with WP_Query […]

Random loop with code to prevent duplicate output returns no output at all from time to time

I have a custom taxonomy with several quotes assigned to each term. Two terms (general and yoga) share the same pool of three quotes. On my front-page.php i randomly draw one quote from each term and display it as an introduction to each section. In the case of the terms general and yoga i’ve included […]

How to filter sql only for a specific post type

I have been trying to join a custom table with a regular wordpress query, but only under a specific condition (a specific post type). I have a single-event.php template that runs the main query, and a secondary WP_Query in the sidebar. Id like to filter the SQL for the main query without interfering with the […]

Overwriting posts_per_page in new WP_Query

I’ve tried for hours for a solution to this. Here’s the problem, I have a theme that is using new WP_Query to set up a loop. That works fine. I want to take the original query, modify it, and then use another custom query to display the modified list of posts. It all works fine […]

Multiple Loops Inside a Function

What I understand from the CODEX, ( then I’m trying to do a list of posts like this: <nav id=”cbp-hrmenu” class=”cbp-hrmenu main-menu”> <ul> <li> <a href=”#”>Secciones</a> <div class=”cbp-hrsub”> <div class=”cbp-hrsub-inner”> <div> <h4><a href=”#” class=”menu-section”>Topic 1</a></h4> <ul> <?php echo get_posts_menus(‘topic-1′,’3’); ?> </ul> <h4><a href=”#” class=”menu-section”>Topic 2</a></h4> <ul> <?php echo get_posts_menus(‘topic-2′,’3’); ?> </ul> </div> <div> <h4><a href=”#” […]