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
2answers
671 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
3answers
1k 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
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
2answers
339 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 ...
1
vote
2answers
112 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
62 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
144 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
1answer
315 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
4k 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
250 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
48 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
704 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
2k 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
160 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
172 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
1answer
1k views

Insert image or ad script after 3 posts using the loop

There are many scripts/hacks out there to insert ads into the middle of the post (after 'x' number of paragraphs), however I haven't found a good enough script that can do the above. This is the ...
1
vote
2answers
435 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 ...
1
vote
1answer
3k views

Get Custom post with ID

How do I get a custom post by its ID? I want to display a single post from custom post using its ID. I tried 'post_type' => 'homepage', 'post_id' => '717' but it didnt work. Thanks
1
vote
1answer
68 views

Check to see if specific loop has less than certain amount of posts

I'm looking for a way to check how many posts are returned by a specific loop. So if I have a loop like this.. <?php $featured_post_id = get_the_ID(); global $post; $args = array('cat' => ...
1
vote
2answers
208 views

How to speed up a wordpress function with multiple loops?

I am a PHP novice and wrote this function. It is an alphabetical navigation which shows only the letter that have posts in both that letter and the currently filtered "genero" taxonomy term. I use ...
1
vote
2answers
174 views

Combining the_excerpt with the_content

I have some html: <div class="container"> <p class="accent">The first paragraph...</p> <p>The rest of the article...</p> </div> I'd like to put "the_excerpt" in ...
1
vote
1answer
426 views

Facebook “like” open graph meta in header.php

I would like to add open graph meta tags to my header.php, but can someone explain how this works if header.php comes before my loop with the relevant information?? <meta property="og:title" ...
1
vote
2answers
150 views

Different style for most recent article

I'd like to make my most recent article display a large with a larger thumbnail and with more content, while the rest of the posts in the loop show a small thumbnail and only the title with no ...
1
vote
1answer
2k views

Dynamically excluding current page id

I'm attempting to create a "related posts" section on pages using query_posts. I'm wanting to use this simply because we want to show random posts from one category on one page, so a plugin would be ...
1
vote
3answers
1k views

Using new WP_Query in shortcode in a custom field causes the main post content to not display

I've got a custom post type of files I'm trying to list using a new WP_Query. It works fine when I add the shortcode within the main post content. However, when I add the shortcode to a custom field ...
1
vote
4answers
776 views

Using one WP_Query object within the loop of another WP_Query object

I'm creating two different WP_Query objects, one for each of two different post types I'm using. In creating my output, I'd like to loop through one of the objects, and at the same time loop through ...
1
vote
1answer
301 views

Custom loop with conditional statement to separate each terms

Let's say for example: I have a custom taxonomy called "fruit", which has 3 terms "apple", "orange", and "grape". So in order to get all the posts within all these three terms, I would : $args = ...
1
vote
2answers
1k views

How to determine if an admin is logged in outside the loop

I need to be able to tell if an admin is logged in ouside of the loop. This is needed for some php files that are part of a WP site but do not use require( '../wp-load.php ); What I need to do is ...
1
vote
2answers
145 views

Finding posts containing matching array elements in a meta field usign WP_Query

I have a metafield, that contains a series of options and writes the results to an array in a single meta field: array([0]=>'First', [1]=>'Second', [2]=>'Third', ); I find ...
1
vote
1answer
3k views

Refine search results using WP_Query

I am trying to modify (refine?) Worpress search results by using WP_Query, just as it's explained in the Codex. The snippet featured in that article is on the top of the Search Template PHP file, and ...
1
vote
1answer
131 views

Varying Search Result Pages

I have two different kinds of search results on my site and I'd like to change the look of the search result page entirely. I've played around with the search form a bit but I'm unsure how to force it ...
1
vote
1answer
631 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
250 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
333 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
970 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
350 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
1k 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
1k 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
442 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
371 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
2answers
49 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
1answer
46 views

Get 10 posts from a WP_Query. If less than 10, get the remainder from elsewhere

I'm trying to create a related posts WP_Query. So far, I've to created a custom WP_Query that queries all posts that match an array of tags. However, I'm trying to create a simple if statement: if ...
1
vote
2answers
32 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
27 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
20 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
47 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
2answers
121 views

Resetting post data to previous loop in nested loops

I'm trying to use nested loops with the posts to posts plugin. The loops both work, but the problem arises after the second nested loop ($issue). I want to access the $publication loop again, but the ...
1
vote
1answer
217 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
283 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 ...