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
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
5answers
3k views

is_home, and is_front_page conditional problem

I have this snippet in a "portfolio-loop.php" file. I'm using get_template_part to display the loop on the front page and on other pages. I have this within the loop: <?php if( !is_home() || ...
1
vote
2answers
14k views

Get post count of current loop when using multiple queries on one page

I'm trying to get a count of the current posts inside of a loop. I'm using multiple loops on one page in my theme. So far I have: $my_post_count = $wp_query->post_count; But when I print ...
1
vote
2answers
139 views

Why is the first query affecting the second query, even after wp_reset_query() and wp_reset_postdata(), but not on the second page?

I am literally clueless as to why the code does not function properly on the first page, but functions as expected on the second page. I have already tried running the second query via another ...
1
vote
3answers
6k views

Override the default number of posts to show for a single loop?

Is is possible to override the set # of blog posts to show per page (as defined under Reading Settings in the WordPress admin)? I want to make it so a custom loop that I am using will show an ...
1
vote
1answer
609 views

Ajax loop in sidebar to load post titles/categories

I have a sidebar that displays the 20 latest posts, what I'd really like to do is Ajaxify that loop so there's a load more button at the bottom. The problem is, it's a fairly complicated loop and ...
1
vote
2answers
2k views

$post>ID displays wrong post ID

I've asked a question about listing all sub-pages before: Listing all sub-pages? But all the questions were wrong. Anyways, I have now simpler question. global $post; echo $post>ID Works ...
1
vote
1answer
2k views

Formating the display of a post's date, outside the Loop

I'm using this function to be able to retrieve several data, from outside the Loop: function get_post_data($postId) { global $wpdb; return $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ...
1
vote
2answers
44 views

All posts are still shown when adding category argument to query

I've got the following code in my team-type.php file which I'm using to create a custom taxonomy for a member information: function create_team_taxonomies() { $labels = array( 'name' ...
1
vote
2answers
303 views

Showing current subcategory

I have problem. <?php query_posts('category_name=events&posts_per_page=2&offset=1'); ?> <?php while (have_posts()) : the_post(); ?> <div> <?php $children = ...
1
vote
4answers
2k views

Loop through all tags & output posts in alphabetical list

I have a bunch of posts that each have multiple tags, and I'm trying to find a way to output all of them on a single page, organized under an alphabetical listing of their respective tags. E.g. if ...
1
vote
1answer
984 views

Adding Pagination on a Custom Author Page

i have created a custom author's page that list the title of their posts. but the problem is i can't get the pagination to work if it's beyond the set post per page value. i have used get_posts() to ...
1
vote
1answer
1k views

Show scheduled posts in archive page

I'd like my archive.php page's daily view (is_day) to display scheduled posts (post_status=future). For example, if I go to mysite.com/2011/05/20 I would see all posts scheduled to appear on May 20. ...
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 ...
1
vote
1answer
97 views

What exactly defines a Main Loop and a Secondary Loop?

My assumption is that the main loop is always the first loop and you're always supposed to use query_post? Is this correct? Then whenever you you need to feed in some arguments to get a different set ...
1
vote
2answers
195 views

Output 2 items within the Loop

I have a query that loops through <li>'s and displays the number of <li>'s I have. Is there a way I can make the loop pull 2 <li>'s at a time rather than one? // 5 list items ...
1
vote
2answers
9k views

How to get posts published between a date and today?

Is it a way to get posts published between a date and today with query_posts() ? Example : All posts published since 2012-04-01 Thanks EDIT : How to add the filter date on this Query Posts ? ...
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 ...
1
vote
3answers
612 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 ...
1
vote
3answers
2k views

Check if post belongs to any category

In my homepage loop, I have something that will show which category the post is in. It will say something like "Posted 4 hours ago in Sports by ...". However, when there is no category set, it will ...
1
vote
2answers
288 views

How do I display the function the_content in this loop?

I have this loop in my wordpress site which displays the latest posts with their titles, I want to display the post content after the title. I normally retrieve it with the function get_the_content ...
1
vote
3answers
94 views

Some doubts about how to show posts in a custom theme?

I am pretty new in WordPress theme development and I have some doubt about this WP function used to show my post in the homepage: <?php if ( have_posts() ) : // Start the ...
1
vote
1answer
193 views

Undefined WP_Query::has_posts()?

This must be wrong. I was testing something so I did: $queried_post = new WP_Query(array('posts_per_page' => 5, 'offset'=> 1, 'category' => 1)); var_dump($queried_post->has_posts()); ...
1
vote
1answer
928 views

How can i display the content in plaintext

i want to display my excerpt in plaintext. How can i do this? This is my Snippet where i display the content: <?php the_content(__( 'Weiterlesen &rsaquo;','okay')); ?> How i change the ...
1
vote
1answer
94 views

Reverse chronology of post listing

I"m working on modifying a theme that is based on 2010. I want to make the posts on this blog display earliest to oldest, but I don't see how to do this in the theme: I understand I need to add . ...
1
vote
3answers
244 views

Force index.php have_posts() loop to exit if no sticky posts found

I'm currently using the code below to list sticky posts on my index.php. However, when no sticky posts are present, its loading the latest posts (up to the number specified in "settings > reading > ...
1
vote
1answer
756 views

Is there any need to use both wp_reset_postdata and wp_reset_query together?

Is there any need to use both wp_reset_postdata() and wp_reset_query() together? Is it a case that I would pick one of the two functions; is there any point in doing this after a query : ...
1
vote
2answers
973 views

get_template_part() - post-meta not working?

Maybe I simply do not understand what get_template_part() is doing … I have a file called event-list.php that should work as template for other pages and files so all my events (a custom post type) ...
1
vote
1answer
825 views

Exclude custom taxonomy tag from loop

I have the following code at the beginning of a loop: <?php query_posts('showposts=3&cat=84'); ?> <?php $posts = get_posts('category=84&numberposts=3&offset=0'); foreach ($posts ...
1
vote
2answers
104 views

Help with Changing loop.php?

I'm trying to edit the loop so if its on category ID 60 it displays "Photos" instead of "Blog".. how do I do this? blog <?php ...
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 ...
1
vote
2answers
5k views

In a foreach loop, how do I target the last item in the loop?

I have the following code to do a foreach loop, I want to target the last item in the loop (e.g if it's looped over 3 events I want to target the 3rd event) to do something slightly different with the ...
1
vote
2answers
803 views

Pagination gives extra page with no results

I'm trying to implement pagination on a category page. The pagination is working, but now for some reason the pagination plugin I'm using is noting one extra page of results, when that page is ...
1
vote
2answers
1k views

category__not_in — anyway to use category name instead of id?

I would like to exclude categories from the loop using the "name" instead of the "id", since the ID can change when using new databases. The name however will always be the same. Is this possible?
1
vote
3answers
24 views

the_content() seems to block my ACF-code

I have this simple code, but can't get the_content and the ACF-code to work together. If I include the_content() it blocks out the ACF-code, but if I remove the_content() the ACF-code works fine. I ...
1
vote
1answer
136 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
93 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 ...
1
vote
2answers
253 views

What are the disadvantages of using global variable?

I am a newbie at WordPress. In my "recent posts" shortcode, I used global $post variable, because the_title() function was giving me page's title, not post's title. I am not exactly sure, but I ...
1
vote
1answer
76 views

if/else on custom query gives 200 OK when condition not met?

What? I am modifying my theme to show comments of a post on a separate page. How? Mostly based on this answer but with improved checks and code. So this is what my page-comments.php (kinda) looks ...
1
vote
2answers
466 views

Store loop into array

I am using folowing code to store posts ids into array: <?php $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => ...
1
vote
2answers
9k views

Woocommerce custom loop to show all the products

I'm currently working on an e-commerce website and I met an problem. My client want a page e-boutique with all the product categories displayed, followed by 3 promoted products and a button "show ...
1
vote
1answer
361 views

Custom search form to display users only

I'm trying to build a custom search form for one of my pages. I need the search form to be able to search for users. Not only will it need to search for users, but by first name, last name etc.. ...
1
vote
2answers
51 views

2 Loops, Only Displaying 1 Loop in Both Loops

I have 2 loops, movie trailers and gaming trailers but gaming trailers is displaying under both Movie Trailers and Gaming Trailer. Each loop displays the post tagged with either Movie Trailer or ...
1
vote
2answers
1k views

the_title() shows title of the first post instead of the page title?

I'm occasionally facing this problem and not sure what causes it, any ideas? <?php get_header(); ?> <div class="content" role="main"> <h1><?php the_title(); ...
1
vote
1answer
984 views

WP_Query: query posts by ids from array?

I did quite a bit of research but can't figure why this wouldn't work for me? echo print_r($rel); // Array ( [0] => 63 [1] => 87 ) $args = array( 'post_type' => array( 'post' ), ...
1
vote
1answer
2k views

Use WP_Query with have_posts()?

Is it possible to use $items = new WP_Query( $query_args ); with <?php if(have_posts()): ?> <?php while (have_posts()) : the_post(); ?> without changing the loop to be <?php ...
1
vote
1answer
4k views

Loop within a loop?

I'm using a couple of custom wp_query loops on my page, the first one retrieves news from a certain category then displays a small excerpt from it with the permalink. The second one is another ...
1
vote
1answer
234 views

Get the author of the latest revision

I would like to display the author (username) of the latest revision of a post from inside the loop. I tried get_the_author(), which echoes the username and $post->post_author(), which returns the ...
1
vote
3answers
238 views

How to add element after every post in the loop, but not the last one

I have a pretty common loop: global $wp_query, $wpdb; if ( have_posts() ) { while ( have_posts() ) { the_post(); get_template_part( 'template_parts/content' ...
1
vote
2answers
544 views

query user display_name failed in a custom mysql query foreach

I met some trouble. I tried to get user display_name in a custom mysql query foreach, but it failed. I have tried three method. new WP_User, get_user_by and get_userdata. but they only can get back ...