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
108 views

Custom Post Type Pagination Not Working On Archive Page

I've spent the last 3 hours trying to get pagination to show up on my custom post type archive page. I sort of understand that pagination only works with a default loop and once you modify the loop, ...
0
votes
1answer
73 views

meta_query not working properly

I'm trying to run a query that only displays items that meet a condition in an Advanced Custom Fields select box, but I'm getting nothing. Here's my query. Any help would be appreciated: <?php $...
0
votes
2answers
36 views

How to Order By Two Custom Fields?

Note : This is not a duplicate question to If value present, order posts by two consecutive custom fields. After filtering a custom filed, I need to order by another custom filed. (The above link ...
1
vote
1answer
80 views

Wordpress have_posts() return false but count says “3”

The situation is this: I have created a custom post type which works perfectly, now I want to create a specific archive page template for the taxonomies of this post type. I duplicated the archive....
-2
votes
2answers
47 views

How to create a loop where loop changes every post?

How can I create a type of loop in WordPress where an image moves left or right for each post? I.e. first post image will be left, second post image will go right, third post image will go left, and ...
3
votes
6answers
4k views

Get date of last update outside of loop

I'm trying to figure out how to display the date that a post was last updated outside of the loop. I'm able to display the published date using get_the_time() but there doesn't seem to be a "loopless" ...
0
votes
1answer
43 views

Adding a html class based on post count

I'm creating a grid of columns and need to add a css class to each column at the end of the loop based on the amount of posts returned so it returns something like this: <div class="column-3"</...
0
votes
1answer
958 views

Search.php - return number of results but cannot loop through

I have a following search.php page (this is just the code required for problem presentation). Why is my $total_results returning a number of posts found, but when I do a loop though it always print ...
0
votes
2answers
76 views

How to display post list in a table layout (multiple queries in single loop)

I am setting up an events page for my website. This page is using a loop to display a list of acts performing at different venues month-by-month. When a viewer comes to the page, they use a simple ...
0
votes
1answer
1k views

group search results by post type?

My site has 3 unique post types: Default Blog posts ("post") custom type "lesson" custom type "series" When the user searches the site, I would like pertinent results from all 3 post types to show ...
0
votes
1answer
21 views

How can I make this iterative conditional within the Loop work via function?

I want an element to appear within the Loop, but only at certain points. I can supply the condition - in the form of a "flag" that gets set when the condition is fulfilled, preventing further ...
-1
votes
3answers
493 views

How can I implement pagination on custom category page?

I have created a custom template page for every one of my categories. I am using a foreach loop in order to fetch the posts of this specific category in my page. if (is_page()) { $cat=get_cat_ID($...
2
votes
1answer
3k views

Display products for a category, sorted by post_excerpt

I'd like to display a list of products for a certain category, sorted by the post_excerpt. The original code I used was this: $args = array( 'tax_query' => array( array( '...
1
vote
0answers
31 views

Infinite Scroll and DFP

Well , I'm trying the next loop to make work DFP in an Infinite Scroll. I thought that if I change the name of the Slot I could get the banner shown, so I tried this: <!-- DFP Controller --> ...
0
votes
1answer
28 views

Posts Per Page is Not Returning Correct Number

I have a single.php with 3 loops one the page (related posts, latest posts and the actual content). All loops are using the wp_reset_postdata(); at the end. For some reason my post_per_page ...
-1
votes
1answer
24 views

How to separate posts loop in to two columns? [duplicate]

I need to separate WordPress posts loop in to 2 columns , left ( all odds ) and right ( all evens ) . Currently I am doing this with 2 separate loops but would like to make it with one and would ...
0
votes
2answers
93 views

Pagination Not working on Home Page with 2 Query

I have two loops in home page (index.php) <?php $args = array( 'post_type' => 'post', 'posts_per_page' => 3, ); $another_query = new WP_Query($args); if( $...
3
votes
1answer
2k 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 ...
0
votes
1answer
23 views

Exclude current custom post on single post

I'm trying to exclude the current custom post that is viewed from a list. I've tried with exclude but it still displays it. Here is the code I have on single-works.php: <?php $currentID = ...
0
votes
0answers
30 views

why does “else” break “if” statement?

I dont understand why this is happening. The winning code is a hash of the post ID. A link is sent to email with the winning code and a link to verify that youre the winner. Now here is where ...
-1
votes
2answers
92 views

How to create a loop that will display one post and stop?

I am trying to create a part on my wordpress theme that will only display one featured post. I have installed this plugin - https://wordpress.org/plugins/featured-post/ . I know I am supposed to ...
1
vote
0answers
82 views

Trying to use AngularJS with WordPress without any API

I understand one can do this using the JSON RESTful API from WP but I don't want to go that route since it only works with sites on Wordpress.com and not on localhost (at least that's what I was told ...
0
votes
1answer
100 views

2 Loops on one page - pagination of 2nd loop ignore array of excluded posts

I have 2 loop on one page. First one shows 11 recent posts in rand order and pushes each post ID into do_not_duplicatearray. $argsRandom = array( 'numberposts' => 11, 'fields' => 'ids' ...
0
votes
2answers
77 views

Display specific page (that is child) content on parent page

I have problem displaying child page content on parent page (both static). I can display other page content but only if on same level. It dosent work in relation parent - child. <?php $...
1
vote
2answers
834 views

Most recent post from another database

I am trying to add the most recent post from another Wordpress database (on the same server in all actuality), but am getting the following error: Fatal error: Call to undefined method wpdb::...
0
votes
1answer
53 views

active link for most recent post on vertical tabs

I'm trying to add the css class .is-active to my vertical tab links inside my loop. By default, the page loads the most recent post first. How can I make most recent tab/post active with .is-active? ...
1
vote
0answers
19 views

Two loops on different pages do the same thing, but only one page works

I want to verify a code sent in an email. I do it once to verify your email when you signup and again if youre the winner of the contest. Since its basically the same thing, I reused the same code (...
0
votes
0answers
25 views

Archive page: how to orderby category and then by author?

Is it possible to display an archive page ordering its articles by (sub)categories first and by author (alphabetically) as second level order? What do I need to modify and where?
0
votes
0answers
26 views

loop authors with permalinks to posts for custom post type

I have created a custom post type called "adoptions", I have created an adoption-page.php and a single-adoptions.php. In the adoptions-page.php I have loop which displays all the current post from ...
0
votes
0answers
68 views

WordPress multiple loops on home optimization

I am running an News Website based on WordPress with several plug-ins, including W3C Total Cache on my VPS (Nginx + PHP-FPM) server. The code of our home.php is: <!-- STICKY POSTS --&...
0
votes
1answer
539 views

How to check if a product is purchased within the last 365 days before displaying something

I have a WP site using WooCommerce. Our products are made up of physical stock, a download and some links to pages on our site. I had set this up by placing the links to the specific product pages ...
1
vote
1answer
587 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
27 views

Loop code is displaying pages but not actual posts

This code only returns the name of a custom page I built -home. Why is it returning the page title? I want to display posts. <?php if ( have_posts() ) { while ( have_posts() ) { ...
0
votes
0answers
36 views

Sticky post to top of category

I use this code: add_filter('the_posts', 'bump_sticky_posts_to_top'); function bump_sticky_posts_to_top($posts) { foreach($posts as $i => $post) { if(is_sticky($post->ID)) { ...
1
vote
1answer
26 views

get_posts that match a user-specified value on a page

On each page, I want the admin to choose which case history post summaries will be displayed depending on the post category. My code below works but it is very clunky if you have lots of categories. ...
0
votes
1answer
343 views

Is it possible to add query parameters on the archive page?

I have a custom post type (works), and an archive page (archive-works.php). I would like to hide the non-public posts from the archive page, so I added a custom meta box. I also modified the query to ...
0
votes
1answer
28 views

List Authors For Current Category

I want to list all unique authors that have posts in the current category. My code (location: wp-content/themes/custom-theme/category.php) <div class="container"> <div class="row"> ...
2
votes
1answer
64 views

Double count view in archive.php

I'm having a hard time using this snippet I'm getting double views each time the post is queried. This is in my functions.php file: function getPostViews($postID){ $count_key = 'post_views_count';...
0
votes
0answers
34 views

WP Pagenavi showing only the first two pages without error

I'm trying to show a complete list of the posts, so I included pagination. The problem is that only it's possible to access the first two pages. If I try accessing the 3rd page(/page/3) for example, I ...
0
votes
1answer
48 views

Infinite Loop after Genesis Theme Upgrade

I'm running WordPress on Microsoft Azure, and I've been having a lot of timeout errors any time I try to install or update plugins/themes. (I'm using a custom child theme, based on Genesis.) Today, I ...
1
vote
2answers
65 views

Display different content on homepage depending on post type

In the home page, I have a custom loop for displaying different post type content. I have this loop on my index.php $loop = new WP_Query( array( 'post_type' => array('photo', 'video', 'web'), ...
0
votes
1answer
89 views

ACF loops false value with repeater and checkbox

I have an ACF repeater field setup on a page and within the subfields I have a True/False checkbox. So far, if the box is checked, it will show the fields. If not then it will not. However, the one ...
3
votes
2answers
69 views

Ignore post by meta value in the main query

I use this function to insert at the beginning of the loop two post at my convenience (with meta key and value) add_filter( 'posts_results', 'insert_post_wpse_96347', 10, 2 ); function ...
5
votes
1answer
128 views

Get ID of a page containing secondary loop in content

I am trying to get the ID (outside of loop) of a page which have a loop of another CPT within its content using a shortcode. If I do a print_r of get_queried_object(), all I get the args used to ...
0
votes
1answer
33 views

Modify widget to output posts in custom order

I am using a widget of the Smartline-Lite theme called "Smartline_Category_Posts_Grid_Widget" that lists posts of a chosen category on the front page. I have set the number of posts to 10. The widget ...
0
votes
2answers
29 views

Can I use both a custom excerpt and a trimmed excerpt?

For each post, I use the custom excerpt field to write a custom excerpt (180 characters max) for each of my posts, which I use as the meta description of my post for SEO. When I show a list of my ...
5
votes
1answer
1k 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 ...
0
votes
1answer
686 views

How to get the first image gallery of a product in woocommerce in a loop

I want to diplay a product with product image, and when visitor hover that image, will change to first image from product gallery I am using this code to display the image gallery, but displayed all ...
0
votes
0answers
18 views

Query a custom post type from a different WordPress install?

I have a client who would like to only create his items on one domain, but have a specific taxonomy of that custom post type display on a different domain (this is not multi-site...they are separate ...
0
votes
0answers
22 views

Use audio file like image featured

Attempt to get the url of an audio file in post content to display in the loop of the home page. I can only get it if the file is uploaded at the time of creating the post, but if I go to a post ...