The core of the WordPress query, the loop offers an easy way to access post information and display it on your website.

learn more… | top users | synonyms (3)

21
votes
1answer
14k views

How to fix pagination for custom loops?

I have added a custom/secondary query to a template file/custom page template; how can I make WordPress use my custom query for pagination, instead of using the main query loop's pagination? Addendum ...
13
votes
4answers
14k views

Pagination not working with custom loop

I've got a custom loop that I'm using to display some Real Estate listings that will be available within 60 days. I'm calling it with the following function: <?php $sixtydays = date('Y/m/d', ...
2
votes
1answer
281 views

Some doubts about how the main query and the custom query works in this custom theme?

I am pretty new in WordPress theme development and I'm not so into PHP (I came from Java and C#) and have the following situation in this custom theme As you can see in the homepage I first show a ...
5
votes
5answers
13k views

How to split a loop into multiple columns

If I have a loop running from a category query like : <?php $the_query = new WP_Query('cat=1&showposts=50&orderby=title&order=asc');?> <ul> <?php while ...
4
votes
1answer
328 views

How to return loop contents

At times, I need to return the output of a loop (usually with WP_Query like in this example) for use in a shortcode or with a filter on the_content. The following code that uses object buffering ...
1
vote
1answer
5k views

Multiple WP_Query loops with Pagination

There are a few other questions about this (and WP_Query pagination seems to be a huge question for a lot of people) so I'm trying to narrow down exactly how to make it function. I'm able to create a ...
2
votes
1answer
704 views

Multiple Loops Homepage?

I have been pretty impressed with the recent redesign at WebDesignerDepot and I am curious about the mechanics of their homepage. I like how they have featured post sections that break up the monotony ...
1
vote
2answers
103 views

Guidance with The Loop for CMS

Maybe I'm going about this the wrong way but this is my scenario... I would like to use WordPress as a CMS rather than a blogging platform. I have a website that will have somewhere between 25-50 ...
7
votes
1answer
3k views

How can I fetch loop of post titles via AJAX?

I have a list of the most recent post titles in sidebar.php. Here is an example of how that code looks: <?php $args = array('posts_per_page' => 20); ?> <?php $sidebar = new ...
3
votes
1answer
2k views

Is it possible to define a template for a custom post type within a plugin independent of the active theme?

I'm writing a plugin to manage data about open-source projects. I developed an object model and have successfully created all custom post types and taxonomies, as well as implemented the correct ...
3
votes
2answers
4k views

WP_Query and next_posts_link

I cannot figure out how to make next_posts_link() work within my custom WP_Query. Here is the function: function artists() { echo '<div id="artists">'; $args = array( 'post_type' => ...
3
votes
1answer
203 views

Have different number of posts on first page

I need to have a different amount of posts per page on the first page that on the other pages. For example, this is what I need Total posts: 6 First page: showing 3 posts Following page: showing 2 ...
2
votes
2answers
1k views

“pre_get_posts” firing on every query

How can I change arguments for the main query only, and not affect other queries? add_filter('pre_get_posts', 'custom_post_count'); function custom_post_count($query){ ...
4
votes
2answers
414 views

Do I need to use The Loop on pages?

I'm writing my first WordPress theme and have a question about the use of The Loop in page templates. The page templates I've looked at all follow basically the same pattern (example from Twenty ...
2
votes
3answers
8k views

How to Change Loop to Order Posts by Views (using wp-postviews plugin)

I hope somebody would be kind enough to help. I currently have a page that orders all of the posts by comment count, but I want to change the loop to order the posts by view count. I have installed ...
1
vote
3answers
628 views

Using the loop inside admin

I have the following issue: I am creating a custom-meta-box for the user to add custom fields in a friendly way. I want to generate a drop-down box with all posts that fall under category 10. I have ...
0
votes
1answer
551 views

How to make multiple Column in archive Page?

I want to create multiple column on archive page but dont want duplicate posts please have look examples http://www.firstpost.com/category/business ...
0
votes
2answers
1k views

Include multiple page ids in loop

Haven’t slept in about 30 hours now, can someone please help as the below code doesn’t work, it just displays all posts etc :| <?php $args = array ( 'page' => array(139, 54) ); ...
10
votes
4answers
3k views

Display all posts starting with given letter?

I'm trying to build Wordpress based dictionary, basically it will have 26 pages (one for each letter): A B C ... X Y Z And every page will display all posts starting with given letter, so after ...
5
votes
3answers
2k views

Split Content and Gallery

Is there a way to split up the post content and the gallery short code. I want to display the gallery outside my normal content no matter how or where it is placed. I can use this to get the shortcode ...
6
votes
6answers
19k views

Get excerpt using get_the_excerpt outside a loop

I have a code that call get_the_title() and it works, but get_the_excerpt() return empty. How can i make it work? This code is inside a plugin called "WP Facebook Open Graph protocol". Here's the ...
5
votes
5answers
11k views

Display all posts in a custom post type, grouped by a custom taxonomy

I’m working on a member page where I use a custom post type with a custom taxonomy. My custom post type is called “member” and my custom taxonomy is called “member_groups”. I want to list all the ...
4
votes
1answer
535 views

How-to exclude terms from the main query the most performant way?

This Q is a follow up to this answer on the Q: "How to exclude a specific term for the search?". 4 ways to filter out posts that have a specific term Type | Pro | ...
3
votes
2answers
4k views

Pagination with WP_Query is buggy - working for some pages, but not the others

I'm having a very peculiar bug with pagination :( I'm trying to display 4 posts per page for a category with slug "lastest-news". The pagination function seems to work correctly. There are 33 posts. ...
0
votes
2answers
4k views

Can i merge 2 new WP_Query($variable) 's?

I am running a multisite network and i have setup a sql query that uses swith_to_blog(); and queries the posts. Is there a way that i can declare the query inside a new WP_Query and actually merge ...
4
votes
4answers
6k views

How do I exclude a custom taxonomy from the post loop

Is there a simple or easy way to exclude all posts from a custom taxonomy in the loop? I've been looking high and low, and neither SE, SO or Google seem to have a straight answer. I know it can be ...
2
votes
1answer
554 views

Listing Parent, Child and GrandChild Categories and then the PostTitles on Page Template !

What I want to do is a loop like this is something like this I'm really sorry but its hard to format here! I going to put this short url http://pastebin.com/dEdKzgJz so you can see it better... Can ...
1
vote
1answer
185 views

Add inline HTML to posts published within last 24hrs

Basically I'm looking to add this line of code to posts published within the last 24hrs: <span class="new">New!</span> When the post is over 24hrs old, remove the inline HTML element. ...
1
vote
4answers
4k views

Exclude the category from the WordPress loop

I have this code for the loop, and I need to exclude a category 4 from this loop. Any suggestions on how to achieve this? Code that starts the loop <?php if(have_posts()): ?> <ol ...
1
vote
1answer
675 views

posts_per_page & pagination conflict

I have a custom query to display my custom post type. posts_per_page set to '5'. In admin post per page set to '10' (settings => Reading => Blog pages show at most 10 posts) My template lists 5 posts ...
1
vote
3answers
312 views

Grossly inefficient wordpress loops!

I'm working on a site at the moment for an orchestra. The various members need to be listed, according to their instrument. The members have a custom post type of biography and I'm capturing the ...
0
votes
1answer
127 views

How to show the posts of some category first, and then all other

How to show the posts of some category first, and then all other posts that does not belong to that category? I have logic that get the category and reorder the posts. But i don't know how to use. ...
3
votes
1answer
1k views

How to add author details in the post sidebar?

I would like to add author details in the sidebar instead of bottom of the post? Can anyone tell me how to do that? As of now i'm using like this in the loop <?php $curauthor = ...
2
votes
6answers
11k views

How to get Author ID outside the loop

I can't get the post author ID outside the loop to make the get_the_author_meta work. So far I've tried different approaches: 1. $author_id=$post->post_author; 2. global $post; ...
1
vote
3answers
472 views

Previous and Next Post link doesn't work

In single.php I tried to add inside the loop the previous_post_link and next_post_link. But nothing is rendered when a view the source of the site. I added the previous_post_link inside an h4 tag to ...
1
vote
3answers
186 views

The Loop in Static Page

I have some questions about the loop. I'm using "twentyfourteen" theme as an example. I'm creating 2 php files with basic loop. One is home.php, and one is a template page called sample-page.php . ...
1
vote
2answers
1k views

Specific Loop For 2 <div> Within Each <li>

I need to create a loop that can logically be described as the following for a carousel: Requirements: 3 Loops 2 Posts Per Loop No Duplicates Order by Post Date Visual: < Start Loop #1 > ...
1
vote
3answers
856 views

Custom post type not displaying content from single-{custom post type} page

I am trying to create a custom post type with taxonomy and a shortcode for my custom search in a plugin.When I activate my plugin I see my CPT and taxonomy on dashboard. But when I publish the post I ...
1
vote
2answers
2k views

List all posts in Custom Post Type but group dynamically by Custom Taxonomies

I have a custom post type named "Resources" which has a Taxonomy named "Types." I have it manually pulling each term which isn't the most elegant solution and every time there is a new term added, I ...
0
votes
2answers
94 views

How to find meta_values to call

This thing has really confused me, when writting a custom query with wp_query we have pass multiple arguments. But i am using woocommerce, and i found this part of query on some form, which is $args ...
0
votes
2answers
116 views

Query date in wordpress loop

I currently have a custom post type called 'events'. I created this from a tutorial here http://tatiyants.com/how-to-use-wordpress-custom-post-types-to-add-events-to-your-site/. I want to query the ...
0
votes
1answer
121 views

Wordpress Alphabetical Glossary close div in loop

wrote this piece of code to make a alphabetical glossary and it works, but there is 1 problem. I don't know how I can end a set of posts with the same first letter. This code looks at the first ...
0
votes
2answers
93 views

Identify the page being shown while in The Loop

In my loop, I'm trying to set it so that certain text is displayed on certain pages, if there are no posts to display. I thought this would be simple, using is_post(), but it seems that this function ...
0
votes
1answer
218 views

Order custom posts by taxonomy?

I have the following custom post types: books, documents, examples, guidebooks, onlineaids. They were generated by the following code: ...
0
votes
4answers
4k views

Multiple loops in same page, without duplicate content

I'm trying to make a page with multiple loops, I need every loop to display a predefined number of posts from the same category (every loop displays X number of posts from Category CATS). But I also ...
0
votes
1answer
162 views

Style every four posts differently [duplicate]

Possible Duplicate: How to mark every 3rd post Is it possible to style every four posts differently? I mean something like this: <div class="row"> <div>1st post</div> ...
0
votes
1answer
193 views

Using jQuery .after inside loop

I have a bit of javascript that will dynamically add a static post to a loop. The script uses the jQuery 'after' method and on a static page it works beautifully but when inside the loop I don't get ...
0
votes
2answers
1k views

WordPress Loop Through Particular Pages

I have the following code setup as a page template and assigned to a page: <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php ...
0
votes
2answers
285 views

Stepping through a foreach loop - adding +1 to the end of it so next time it loops it starts on item 2

I'm creating a custom Google map that plots multiple markers. View the link as it will make it easier to explain what is happening and what I want If you click on each marker it shows company names ...
7
votes
5answers
17k views

Get post content from outside the loop

Is there a way to get the content from another outside the loop? The ID is 302 and I need to display the content of that on another page.