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)

1
vote
1answer
666 views

Custom excerpt function re-factoring

This may be more of a php best practices question, but here goes... I am using a custom excerpt trim function: function new_wp_trim_excerpt($text) { // Fakes an excerpt if needed global $post; ...
1
vote
1answer
265 views

Differentiate between posts and pages in search results

How can one differentiate between posts and pages in search results? What I need to do is show a the_time div for posts but not show it for pages, as it's irrelevant. With a function? <?php if ...
1
vote
2answers
350 views

Why would in_category only return one post in a specific category?

So... what I'm trying to do is simple - get the post content for all posts, but only in a given category. Simple - filter the loop using in_category. So I did this (this is actually a stripped version ...
1
vote
2answers
1k views

Adding 'current_post_item' class to current post in the loop

I'm using a loop in the sidebar of my site to show all the posts that are in that category. Now I'd like to include a 'current_post' class to the current post that is being displayed to style that ...
1
vote
2answers
355 views

Multiple loops on the same page removing post tags

I am trying to use two loops on my page, one to get the current page's content and so on, and another to get all of the posts of a specific category. When I do that, all of the tags for the current ...
1
vote
1answer
1k views

Is it possible to query_posts using post__in and then Loop through them in the ordered they were queried?

query_posts( array ( 'post__in' => array( 5, 76, 21, 56, 3 ) ) ); I'd like to query the Loop using post__in and a set Wordpress IDs. I'd then like to run through the Loop in the exact order of ...
1
vote
1answer
2k views

Custom Post Type Loop within Shortcode

I'm really at loss as to why this isn't working: I am using a shortcode to display a query on a custom post type + taxonomy, this is the segment of it: // - arguments - $args = ...
1
vote
1answer
2k views

How to insert content from another Custom Post type into Post?

Say I have a custom post type called "Performers". This gets populated with different bands/performers. These posts have a featured image as well as custom fields (mp3 file, facebook link, myspace ...
1
vote
3answers
481 views

get the image of the post

Im running 'the loop' and I want to get the image of the post (in original size - not thumbnail), how do I do it? thank you.
1
vote
1answer
374 views

How can I show the post thumbnail from the most recent of a certain post type, in widget?

I'm using the excellent PHP Code Widget plugin, and want to create a widget that displays the post thumbnail (aka featured image) for the most recent 'project' post. Here's the code I have so far, but ...
1
vote
1answer
79 views

Loop starts from the beginning with second while loop on author.php

I am using the same template for author.php and home/blog.php. I have a loop split into 3 parts. <?php if(have_posts()): the_post; //do a thing endif: $i = 0; while(have_posts()): the_post(); ...
1
vote
2answers
325 views

Including all terms in wordpress tax_query

I'm a little bit confused, why I can't include all the terms in tax_query automatically? My code: 'tax_query' => array( array( 'taxonomy' => 'city', 'field' => 'slug', ...
1
vote
2answers
121 views

Display content from custom post type if match to main post category

I solved the problem of displaying from a custom post type in a post with this solution, however, I want to filter even more and only display the posts from custom post type that match the main post's ...
1
vote
1answer
60 views

First post of each category

I'm trying to create a simple loop, that gets the latest post of 3 selected categories. I've searched for something similar to learn from, but most are overly complex. At the moment, I have: ...
1
vote
1answer
22 views

How can I modify the loop from a plugin without wiping out other filters?

I am trying to modify the_loop output from a plugin. I've looked into pre_get_posts, which definitely works, but I need to filter the loop by a custom taxonomy. I can do this with ...
1
vote
1answer
67 views

Query custom post type in the loop

I have a custom post type running called services: // Services function services_cpt() { $labels = array( 'name' => _x( 'Services', 'post type general name' ), ...
1
vote
1answer
352 views

Show newly added posts since last user login time /date

I'm looking for a solution to create a custom loop which will only display the last added/ modified posts since the last user login to the site. It shouldn't be that complicated doesnt it ?
1
vote
1answer
469 views

Operations with custom fields values in a loop

I have a foreach for displaying all the post in one taxonomy filter by terms. I have a custom field for display a numeric value. What I need, is to make two math operation with all the values of that ...
1
vote
2answers
99 views

echo current taxonomy id for this loop?

I have this query to get posts and show like this: Custom taxonomy 1 <div ID1> |-- post 1 |-- post 2 </div> Custom taxonomy 2 <div ID2> |-- post 3 |-- post 4 </div> ...
1
vote
1answer
178 views

IF statement in a do_shortcode

Is it possible to do a if statement in a do_shortcode? <?php echo do_shortcode("[table width='500'] " . if ( have_posts() ) : while ( have_posts() ) : ...
1
vote
1answer
69 views

Create a loop that gets pages with their template

I am trying to make a template that will be an html5/ vertical scrolling base. I have created an amount of page templates that each would represent a <section> on index.php which mainly all it ...
1
vote
1answer
442 views

How to display 7 most recent days of posts?

I would like to be able to display on my homepage a timeline of posts from 7 of the most recent days. For example, if today is January 1, 2013, I would like my blog feed to display something that ...
1
vote
1answer
365 views

Get titles of all posts with current tags except current post

I am trying to print out a bulleted list of all posts in the current posts category (i.e. "siblings") except for the current post itself. I have been able to get the tags of the current bost and ...
1
vote
1answer
141 views

How to adjust code to refresh a dropdown box with tags that are active on filtered category listing

I have multiple custom tags setup (ptags) and custom posttypes (products) and made it so i can filters posts by multiple tags in a category. Currently the code retrieves tags from posts relating to ...
1
vote
1answer
264 views

Count singular post views automatically

I'm trying to add some function to each loop called in the themes. What I'm doing is I add a function to count post view from here post views without plugin, to use the function I need to add this ...
1
vote
1answer
173 views

Loop after page content

I just upgraded to 3.4.2 from 2.9 (i know, i know, but if it ain't broke...) I have page templates that are (or at least were) set up to display the page content first, then start a loop of posts, ...
1
vote
2answers
538 views

Load comments per post on click with AJAX

I'm working on a theme that uses a slider to display blog posts. Beneath the slider is a pagination that displays like a timeline, with a date instead of a page number, calling the corresponding blog ...
1
vote
1answer
179 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
1answer
272 views

using new WP_Query in save_post function alters $post

I'm trying to include a WP_Query in a save_post function for a custom post type. The query is used to check all the other posts for a custom field bh_shortcode to make sure the content of the field is ...
1
vote
1answer
193 views

Function to show only first instance of shortcode

I need to add a function to my theme to remove additional instances of a shortcode in a post. First off I wonder if i'm approaching this wrong, but I have a theme that is drastically reformats the ...
1
vote
1answer
120 views

the_excerpt not showing posts

I'm using the following code to show the single most recent post on my landing page: <?php if (have_posts()) : ?> <?php if (($wp_query->post_count) > 1) : ?> <?php while ...
1
vote
1answer
38 views

Displaying the last page of posts

I'm using a custom loop to display posts using pagination. My query shows 4 posts per page, and there are 4 pages, so 16 posts in total. Is it possible to load in the last page of posts first? So when ...
1
vote
1answer
820 views

Display category posts grouped by taxonomy

I'm working on a project where I use the default posts as "Products", default category as "Application" and a custom taxonomy called "Groups". I want to list "Products" by "Application" ...
1
vote
1answer
318 views

How does the ternary operator work in the wordpress loop post?

Okay so I kind of understand that ternary operators work like condition ? TRUE : FALSE However I'm looking a simple loop to get my posts that I have <?php if (have_posts()) : ...
1
vote
1answer
578 views

Merge two WordPress installations into one, and keep posts separated?

I have two Wordpress installations that I would like to make into one installation, but still keep the posts (and their meta-data) separated. Both installations currently share the same database. I ...
1
vote
1answer
1k views

wp alchemy multiple image uploader output images to template

I am using wp alchemy to add a custom metabox to my site with multiple image uploader option. This part is working fine, but I have no Idea how to go about outputting the image links to my template. I ...
1
vote
2answers
930 views

Single page site (Wordpress) including posts

I'm creating a single page site and obviously want to include the blog posts. I'm currently looping through the pages and using the_content() and the_title() to display them. However, the_content ...
1
vote
2answers
601 views

Pagination on 2nd loop

OK, I am creating a business listing site that is using a custom taxonomy for the listing "type". I need to display two loops on the taxonomy archive page, one for "sponsored" listings and one for ...
1
vote
2answers
1k views

Very Slow Page - How to Optimize # of Queries?

EDIT 12/19/2011 Thank you again Ijaas. Everything is working except for the order of the days. It is ordering the groups of days by the publish order. If an older post has a newer date in its ...
1
vote
3answers
572 views

Why am I getting an infinite loop with have_posts?

I have the following code, which causes an infinite loop for some reason. Can anybody explain what's going on please? Thanks! <?php $flagged_stores = new WP_Query( array ( 'post_type' => ...
1
vote
2answers
1k views

wp_list_categories: get latest featured_image of category

I was thinking about a nicer way to display the categories in my sidebar. Instead of a plain list style, I'd like to have images / thumbnails show up as well. Currently I'm using the following: ...
1
vote
1answer
56 views

I've been out of the loop since 2.8. What did I miss?

I haven't done any serious WP development since version 2.8, although I fiddled a bit with version 3.0. Short of reading the release notes on each version, what are the major things to take note of ...
1
vote
1answer
147 views

Help with Wordpress Query

I'm sort of a noob when it comes to Wordpess; I've only recently started building themes and I've run into a wall. I'm trying to feature 3 different articles at the top of my site using wpquery and ...
1
vote
1answer
594 views

Filtering post-formats from the loop using new WP-Query();

Hi i am currently building upon a theme that i have build previously for my blog. The following code is to point to the latest post (the featured post). As this will have a different styling than all ...
1
vote
1answer
2k views

Displaying the number of posts in a custom loop (without including the number of posts of a loop below)?

I have this custom loop: <?php // Display the top ones $args = array( 'post_type' => 'reply', 'post_parent' => $post->ID, 'r_sortby' => 'highest_rated', ...
1
vote
1answer
412 views

PHP loop that selects posts with a particular in-post option

Im trying to build a Featured post slider to show any post that i mark as a "featured" (with a in-post option) regardless the category or tag type... Im new to wordpress and although I understand a ...
1
vote
2answers
614 views

query_posts() ALWAYS displays something?

OK, I'm using posts_query() to display posts. The problem is, at least in my case, posts_query() always outputs something. For example: <?php $paged = (get_query_var('paged')) ? ...
1
vote
2answers
2k views

get_template_part and template file names

I have a custom post type that is going to use a loop in a couple different places and I wanted to make maintaining those loops easier. I remembered that get_template_part() is available and figured ...
1
vote
2answers
843 views

Breaking the loop?

WP loops are widely used to print lists of posts in Wordpress: <?php $loop = new WP_Query( array( 'post_type' => 'ff', 'ff' => 'show_ff', 'orderby' => 'menu_order', 'order' => 'ASC' ...
1
vote
1answer
617 views

Can I create a loop with multiple post types and specify different $args for each post type?

I'd like to create a custom loop that includes all Post types: Post and Video. Then I'd like to specify to show all posts of the post type Video, but only show posts that are in the category ...