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)

0
votes
1answer
31 views

Why is this coming back as null? Thats wrong. There is one post

I have a category, called events. It is assigned to one post. So I created the following loop: $args = array ('category_name' => 'events', 'posts_per_page' => 4, 'orderby' => 'date', 'order' ...
-1
votes
1answer
26 views

Why am I getting posts back when I shouldnt

I have the the following variables being populated: $posts = wp_get_recent_posts(array ( 'numberposts' => 4, 'post_status' => 'publish' )); $categoryPosts = wp_get_recent_posts(array ( ...
1
vote
1answer
48 views

Pagination returns 404 after page 20

I got a paged loop that pulls in 4 posts per page from custom post type. It works great, with the only downside that the pagination wont go over the page/20 everything after that is 404, and the ...
0
votes
1answer
38 views

get_template_part for custom post type content not working

I have a custom post type of Textorial with necessary template files: textorial-type.php single-textorial.php content-textorial.php The idea is to have a custom layout for the post type and use ...
0
votes
3answers
30 views

Query & the_content() is showing in the header

This post is about two things: All the results of this query are posting to the header of the Page not on the content area as they should. Do you know of a solution as to why this is happening and ...
0
votes
0answers
41 views

WordPress ignoring LIMIT / posts_per_page despite being in wp_query

Using WP query: $myquery = new WP_Query( array( 'posts_per_page' => $instance['count'], 'meta_key' => 'mywp_post_views_count', 'orderby' => 'meta_value_num', 'order' => ...
0
votes
1answer
19 views

Use post in multiple places on a page with multiple posts

I have three custom post types: workouts, news_items, and business_items. I'm trying to display the top (most recent) item from each on the home page and I'm trying to put the featured picture from ...
0
votes
1answer
29 views

How to extract information from a wp_query result?

Background: I'm using a wordpress theme called skt full width. I am modifying their front page slideshow, so that it displays six random images instead of six pre-selected images. I have a custom ...
0
votes
1answer
21 views

How to get to a specific position in wp_query?

Background: I'm trying to display images in a slideshow, and I want to select those pictures randomly from the website's media. The image has a custom field in order to be selected for being the ...
0
votes
1answer
18 views

query_posts clarification needed

I understand for the most what query_posts does and how it works. I also know it's not good practice to use it. But I would like to know exactly what the "$posts" variable does in this setup: ...
0
votes
2answers
115 views

Posts in Multiple Columns and Rows with one single loop

I'm pretty new to creating my own theme and I seem to have become stuck and would really appreciate it if someone could help me. I have searched and found snippets of advice but nothing that really ...
0
votes
2answers
59 views

How to access $wp_query object from array of posts given by get_posts?

I have a simple custom query driven by get_posts: <ul> <?php $args = array('post_type' => 'event', 'numberposts' => 6 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : ...
0
votes
0answers
50 views

How can I display excerpts of my Recent posts on my static homepage?

I am using the openstrap theme. I want a static home page on my Wordpress website, I have already set this up and have a bit of content on it, the next step is I want to have atleast 4 most recent ...
0
votes
1answer
39 views

List all Custom Post Type posts excluding certain Taxnomy term

I'm writing a theme in which I've registered "Services" as Custom Post Type that supports "Type of Service" Custom Taxonomy. I want to list all the posts of type "Services" except those which have ...
0
votes
1answer
42 views

Function using get_posts() with tax_query not working when called from functions.php

I want to get an array of all the 'bands' in taxonomy 'types', and use the array later on in other functions etc. I have a utilities.php file that I require() in functions.php and it has the following ...
0
votes
1answer
25 views

Display the latest post from some selected authors

I'm building a slider that will display the latest post of a few selected authors. So far, I've written this: <?php $args = array( 'post_type' => 'post', 'posts_per_page' ...
0
votes
0answers
66 views

Might be impossible - conditional bootstrap rows in WordPress loop? Currently have 2 loops

I finally got a Bootstrap posts grid I'm happy with for this video portal site. Before I was having a lot of issues with posts never lining up correctly, or if the title above it was too long it ...
0
votes
1answer
41 views

Loop for sticky posts

I used Justin Tadlock's tutorial on how to create a loop consisting only sticky posts. The code looked more or less like this: $sticky = get_option( 'sticky_posts' ); rsort( $sticky ); $sticky = ...
0
votes
0answers
28 views

Multiple Post Repeat for Related Post Loop by Category

This is my code: if ( is_single() ) { $categories = get_the_category(); if ( $categories ) { foreach ( $categories as $category ) { $cat = $category->cat_ID; ...
1
vote
1answer
22 views

Accessing loop functions (e.g the_title or the_content) from post ID

I have an array of post IDs obtained through complicated filtering code. I want to display posts from these IDs, and for each post I need access to regular post functions like the_title and such. More ...
0
votes
2answers
44 views

display news with pictures 3 small and one large (loop)

I'm trying to put 4 news with pictures 3 small and one large, have gotten displaying them but the "large" is repeated with the last "small" <?php $b=1; $args = array( ...
0
votes
0answers
35 views

Blank page with custom loop

in my WordPress theme with two custom loops there is always one blank page at the end when I page through the content. E.g. when I actually have only three pages filled with content, I can access a ...
0
votes
2answers
34 views

Infinite Redirect Loop after moving to subdirectory

I installed WordPress locally and created a theme, which worked fine. Now, as I wanted to deploy the site to a webserver via FTP, I got stuck by an 301 Redirect loop which makes it impossible to ...
0
votes
1answer
33 views

How to exclude a specific categogy from a custom page template

I have a custom page template that uses the wordpress loop to display all my posts like usual: <?php if (have_posts()) : while (have_posts()) : the_post(); There is a category that I don't want ...
-1
votes
1answer
78 views

display custom post type from register taxonomy

I've created a custom post type via this function: function custom_post_type() { $labels = array( 'name' => _x( 'advertising type', 'Post Type General Name', ...
0
votes
1answer
18 views

Showing content from Wordpress ruins page CSS using WP_Query, without, content does not show

I suppose I have a two pronged issue here. I'm trying to show wordpress posts on my own site. I have a page where people can view the list of articles, then when they click on one it takes them to the ...
0
votes
1answer
129 views

How to get_template_part using AJAX?

I'm currently on the Woocommerce archive-product.php template file (say shop page or product category page). On the click of the post (or product), a GET query is added to the title of the same page, ...
0
votes
1answer
27 views

Iterate through ID's in loop

I have created a custom loop based on category, now I would like to run a function with the specific ID of the current post being iterated through as a parameter. I have.. $secondary_loop = new ...
4
votes
1answer
82 views

How to get order of posts?

How can I get the order through which the query is done? For example, my woocommerce product archive page is querying by ordering according to the order_by select box (as seen below). How can I get ...
2
votes
1answer
67 views

How to bring specific post to front of wordpress loop?

So, I have a WordPress loop going on. The below code is the template page for the woocommerce product archive page. Here's the use case for what I am trying to find out how to achieve: User is ...
0
votes
1answer
31 views

Secondary loop doesn't work

Hi I got a problem with my secondary loop in my template page.php. I'm trying to display some testimonials, the code that retrieve those testimonials works perfectly fine in my index.php but I won't ...
0
votes
1answer
30 views

Update status of all posts in a category

For one of my project I just want to change the post status of all the posts inside a specific category from publish to pending. It is possible to change status of multiple posts at once? I want to ...
0
votes
1answer
55 views

Stuck in the query loop

I created a two loop into my WordPress page. It should get the category name and should load all the child under the Category name. Like this ____ Cat1 ______ product 1 product 2 product 3 ____ ...
0
votes
0answers
24 views

Additional custom loop on the “category” page?

i'm having trouble trying to add an additional loop of my CPT inside my "category" page. What im trying to do: first display the latest post of my CTP, then show the posts from the category normally. ...
-3
votes
2answers
45 views

How to split the loop every 2 and 5 results? [closed]

im trying to display my WP loop with this layout: (POST 1) (POST 2)/ (POST 3) (POST 4) (POST 5)/ (POST 6) (POST 7)/ (POST 8) (POST 9) (POST 10) and so goes on. Any ideas? Thank you very much.
0
votes
1answer
25 views

Loop through all posts in a certain year

I would like to loop through all posts within a certain year. Pretty simple setup: <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> // doing content stuff here <?php ...
0
votes
0answers
51 views

Sorting is not working in wordpress WP_Query

i have created a page where i am sorting the post according to the views. Here is the query <?php $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); ...
0
votes
2answers
59 views

Loop through pages with specific template

I would like to know how I can loop through pages with a specific template name. I have several pages where the admin can select a template name of SALE. I want to display all content with this ...
0
votes
1answer
36 views

Loop returning only 1 result

I am not sure as to why when I run my loop only 1 result returns. Here is my code: <?php if ( is_front_page() && twentyfourteen_has_featured_posts() ) { // Include the ...
6
votes
2answers
226 views

How to force excerpts / teasers in the loop

When I'm in "the loop" (archive pages etc.) how do I force teasers / excerpts for all articles, regardless of whether they contain the <!--more--> tag or not? Details: I'm starting off of the ...
1
vote
0answers
39 views

Conflict with get_posts and the_content

I have this snippet in my header.php to display a slider: <?php $args = array( 'post_type' => 'post', 'posts_per_page' => 6, 'meta_query' ...
0
votes
1answer
71 views

WP_Query condition affects posts_per_page count

I'm trying to create a new WP_Query that displays the last 5 posts from cat 1 that doesn't have a thumbnail. This actually works: <?php $the_query = new WP_Query( 'cat=1&posts_per_page=5' ); ...
1
vote
1answer
43 views

Creating Accordians in Wordpress Theme

I am creating a wordpress theme in which there is a section "HUMOUR". In this section i've created accordians, in which the 1st accordian is in class="active" and rest don't. for e.g <dl> ...
0
votes
1answer
177 views

Need to add class to first element in a foreach loop

I'm pulling all attachments for this particular post and displaying them in a carousel. Problem is I need to give the first item a class of active so bootstrap carousel will work. Here is my loop: ...
0
votes
1answer
33 views

How to output thumbnail twice in a loop

ok I have a portfolio page. & I have two question: number 1: Every portfolio item has thumbnail attached. what I want is to print out the first thumbnail from the first post twice. One at the ...
1
vote
1answer
26 views

How to target thumbnails of the first post in the loop

ok currently my last post's thumbnail have an extra class, which were added by this code: <?php $extraLastClass = $loop->current_post + 1 === $loop->post_count ? ' main-image-porfolio-main' ...
-1
votes
1answer
28 views

Want to images load first then title in WordPress loop

ok I'm creating a portfolio page. I want all the images of the portfolio post stack together. & when visitors hover their mouse in any of the title the image ll show. for this I've created this ...
-1
votes
1answer
31 views

How to add class to the last image of the last post in a loop

ok, I'm creating a portfolio page, I want add a class to my last portfolio thumbnail. currently I have a class added to the div of the last portfolio item. I want to add it to the thumbnail, not the ...
0
votes
0answers
39 views

Add custom WP_Query after the first 3 posts

In my main loop I want to add a custom query after the first 3 posts. I managed to do this -- code will follow -- but I have one problem: instead of adding the new posts after the third post, my code ...
0
votes
0answers
10 views

Loop tags with specific design

Forgiveness for the title, I can not think of anything to describe it. First I have a basic loop: <?php $args = array ( 'category_name' => 'juego-de-tronos', 'orderby' ...