Questions tagged [loop]

The core of the WordPress query, the loop offers an easy way to access post information and display it on your website.

728 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8
votes
0answers
6k views

AJAX with loop filtering categories

I've been researching on how to make my loop with AJAX. I found some codes online and modified some parts but I can't seem to get it to work. This is my code for the loop: <article id="main" ...
4
votes
0answers
1k views

Loop that displays PARENT PAGE & CHILD PAGE & outputs GRANDCHILD PAGE title and content

I've never posted here, but I'm tired of slapping code together. That said, I would be most appreciative if someone could help me with this. I need a page template that: outputs the PARENT PAGEs, ...
3
votes
1answer
40 views

How do I get the total number of categories in a list of search results?

I want to display the total count of categories in a set of search results. For example, "10 posts found in 3 categories." (Assuming that each post has only 1 category.) Right now, my solution is to ...
3
votes
0answers
836 views

Show all parents and children in custom post type in right order

I would like to show all posts from a custom post type on one page with the ordering exactly like in the backend. I get the right ordering with wp_list_pages, but of course without the content. ...
3
votes
0answers
53 views

Showing random content / pictures from earlier posts in a sticky post?

I have a sticky post on my wordpress blog, in the beginning. I would like to place some random content in it, by simply replacing some HTML in the post content. The random content would come from ...
3
votes
1answer
979 views

Custom Loop and Infinite Scroll

I am using customized version of _s theme where I have Product CPT. In the following files, I need to use Infinite scroll (provided by Jetpack) - archive-products.php taxonomy-[tax-name].php ...
3
votes
1answer
431 views

Query Custom Meta Value with Increment

I have a Query searching for a meta value I have added to my posts (meta-select). I have it feeding out in a loop with 4 results. Let's say I want this loop to start with the meta value "2" and work ...
2
votes
0answers
44 views

Multiple WP_Query loops with Pagination Not Working

Please can anyone help me out here? I'm really stucked with this code. I want to create a multi post loop on my home page with each loop having its own pagination. The first loop is for recent post, ...
2
votes
1answer
201 views

Show all posts in sidebar in single.php

Wordpress 4.x Why does the loop.php only show the current post in the sidebar when I view a post in single.php? I have: Post One Post Two Post Three If I view "Post One" (single.php), the sidebar ...
2
votes
0answers
23 views

Fix inefficient loop breaks post.php on form submit

As is, this loop works fine. Although I feel like its inefficient because it doesnt need to keep updating the nonce counter each time it loops, that only needs to be done once. So when I try and move ...
2
votes
1answer
2k views

AJAX handler throws 400 (Bad request) - why?

I am trying to apply a "Load more posts" function to a post loop, but I am dealing with a 400 Bad request, when admin-ajax.php is referred to. The reference I used is this - https://rudrastyh.com/...
2
votes
1answer
121 views

wordpress post loop in javascript

How can I put WordPress post loop Codes in javascript? function top_news() { echo '<div class="news"></div>'; $query = get_posts(array( 'showposts' => 3, 'type' => 'topnews' ...
2
votes
1answer
99 views

Category archive page - loop through posts of certain tag (with pagination) - pre_get_posts

I have a category archive page (press), which I need to loop through posts of a certain tag (magazines). I tried to modify the query with pre_get_posts, but it is still just showing posts in the '...
2
votes
0answers
246 views

How to use max and min values of custom fields

How to use max and min values of custom fields (created via ACF, repeater type)? For axample, I've custom post type 'auto' and there are a lot of models. Each post(model) has few values of price (...
2
votes
0answers
48 views

How to iterate through database until it find a match

How can I loop through my Wordpress query, and check each posts if one meta_value of meta_key user_ip_reservering match the $ipadres Code $args = array( 'post_type' => 'reserveringen', )...
2
votes
1answer
194 views

connect last post with first post

next/prev from my first to last and the other way around cant find a solution for that i am using this code for next <?php next_post_link('%link','<img src="img-location"/>'); ?> and ...
2
votes
1answer
169 views

Two loops by pre_get_post on same page

I have two loops in archive.php, both are affected by pre_get_post. My code on pre_get_post is this: // My pre_get_post function my_pre_get_posts( $query ) { if ( is_admin() || ! $query->...
2
votes
1answer
418 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';...
2
votes
1answer
54 views

Lists Posts from CPT that match the Title of the Page

I am trying to get all the posts associated with the Title of a page. This is what I currently have: <?php $title_to_tag_posts_query = new WP_Query( array( 'tag' => ...
2
votes
0answers
707 views

Custom Loop through category menu to include sub categories

In my custom wordpress theme I currently have the below loop to the main categories <?php $menu = wp_get_nav_menu_object('navigation'); $items = wp_get_nav_menu_items($menu->term_id); foreach($...
2
votes
0answers
50 views

Show top level comments ordered by number of replies

I am trying to modify the comment loop initiated by wp_list_comments to change the order they are returned. Specifically I have 2 levels enabled on my comments (top level and replies), and I want to ...
2
votes
0answers
997 views

WP_Query Order by Specific Post ID First

I'm creating a website where I have a need to show a set of posts from a custom loop but I need to display a specific post first. This post will be dynamically specified in the URI by a $_GET ...
2
votes
0answers
211 views

Divide Loop Into Days & Categories

If you could help, I'd greatly appreciate it, because I'm halfway there, but I'm currently stuck! The site I'm working on needs to have it's posts, within the loop, divided up by days, and then under ...
2
votes
0answers
1k views

multiple loops with pagination on the same page

I'm searching the web for this answer for three weeks now. Tried many things but nothing seems to work as how it should work. There must be a kind of trick what probably won't make sense to anybody ...
2
votes
1answer
381 views

Converting multiple loops into one single loop with pagination

I am using Isotope jquery plugin to filter/sort posts in Wordpress but to correctly filter the posts into the right order I have needed to output each category one after the other. To do this I've ...
2
votes
0answers
84 views

Display posts with comments closed, with pagination?

i'm using a custom query, which needs to display all posts with closed comments. I have this <?php $the_query = new WP_Query('showposts=-1'); ?> <?php while ($the_query -> have_posts()) :...
2
votes
1answer
253 views

Replace default Wordpress search behavior with Sphinx

I want to implement Sphinx Search in my Wordpress site but I'm not exactly sure how to change Wordpress search behavior to use Sphinx. How do I get Sphinx Search engine to replace whatever Wordpress ...
2
votes
2answers
67 views

Display custom field of specific post where post title matches variable

I have a custom post type called vacancies and another called our_homes How do I get the google map coordinates from our_homes and display inside the vacancies single post template? My attempt below ...
1
vote
1answer
19 views

Including post thumbnail url in loop's post object to reduce number of queries

I'm working now on high performance Wordpress website and it requires me to analyze a lot of queries, caching options etc. I've discovered that if you use get_the_post_thumbnail() even within the loop,...
1
vote
0answers
69 views

Blog page pagination is not working after using the offset argument

I have displayed the recent 7 posts then shown the remaining posts. So I have added the offset = 7 in the argument to skip above 7 recent posts and display remaining posts but the pagination not ...
1
vote
2answers
20 views

Show post page only if the user has bought a specific product

I'm having troubles with Woocommerce. I need to sell videos. I've created virtual products with a link to a different post for each (no download as I prefer to embed the video on my website and to use ...
1
vote
1answer
27 views

A to Z List of Custom Post Type in three columns

I want to display custom post types A to Z Index in three columns, but it just lists the first post under each alphabet in three columns, I think there is some issue with the loop but can not figure ...
1
vote
1answer
19 views

WordPress loop: exclude if it is the latest post

I do not want to show the latest post on a particular page. I am using a loop per category as I require these loops on various pages. So the thing is, I am running 3 separate loops for each category, ...
1
vote
1answer
27 views

Posts will not display on page-mypage.php

Something is really tripping me up. I have been used to querying posts via custom queries however based on research lately I have learned that for the most part this is a big no no. So, in testing the ...
1
vote
1answer
12 views

How do I go about looping through a advanced custom field on a particular page inside of another page

I have one page lets call it page-home.php and I also have a page called page-custom-field.php I want to have a section of the first page where it loops through page-custom-field.php page and display ...
1
vote
0answers
156 views

Remove product category placeholder image (Woocomerce)

I'm trying to get rid of placeholder product category images on the shop page. Right now I'm using this code to add a .no-image class to products that don't have an image so I can style them ...
1
vote
0answers
49 views

How do I use AJAX Query in my posts loop?

I have this function in my functions.php. All the AJAX and Query is working but displays the results of the loop right below the AJAX filter. I want the query loop to display in my main theme's ...
1
vote
1answer
42 views

What's the WP way to load remaining custom posts?

I am displaying custom post types, grouped under their custom taxonomies (basically used @ChipBennett's answer from here: Display all posts in a custom post type, grouped by a custom taxonomy) for a ...
1
vote
0answers
63 views

Apply an Incremental Counter in an Array Function

I'm attempting to incorporate an incremental counter inside an array function, that is, in turn, inside the post's while loop. However, I am only able to get it to count to 1. This is what I ...
1
vote
0answers
190 views

Calling & display certain product category loop and pagination on the homepage

Need some help with wordpress and woocommerce functions. OK, the situation is, I have a homepage that use archive-product.php template. It shows latest 28 products per page. This is the product loop ...
1
vote
0answers
61 views

How can I add extra word in permalink when someone click download button?

I am new in here. I actually do not understand really it a WordPress related question or not. I think it is. My site runs into WordPress. My question is when someone clicks my post it shows a download ...
1
vote
2answers
228 views

WP_Query to loop a Custom Field, Custom Post Types do not show

I am using WP_Query to loop a Custom Field, Custom Post Type that shows 6 Menu Icons across 6 horizontal fields. The icons do not show on the page. My query code is: <?php $loop = new WP_Query( ...
1
vote
1answer
99 views

Order by empty custom field

I order my posts by custom field faq-order. That's work for me: $faqArgs = array( 'post_type' => 'faq', 'meta_key' => 'faq-order', 'order' => 'ASC', 'orderby' => '...
1
vote
1answer
34 views

How to show “teaser” posts on blog / archive pages, otherwise full posts

Forgive me, I'm a PHP noob and writing too much of it makes my eyes glaze over; I'm sure this is a super simple solution and probably a dumb question. I'm working on a custom theme where I want to ...
1
vote
1answer
564 views

Ajax Infinite Scroll In Custom WP_Query Loop Not Working

I have set up a custom WP_Query loop for a page template. I am implementing an infinite scroll method via ajax, and the call is successful, but for some reason I cannot get the query to like the paged ...
1
vote
0answers
456 views

posts_per_page not working for first page of pagination

I am displaying WordPress posts on my home page and using pagination for these posts. I am limiting number of posts (10) using posts_per_page. But still there are 90+ posts on first page but on all ...
1
vote
2answers
137 views

WP Query with categories only shows one post and ignores the category

I'm trying to make the following mock up with WordPress: https://imgur.com/a/Sem7y I created a custom post type and I created two categories (general and filling instructions). I used ACF plugin to ...
1
vote
1answer
41 views

What to and how to proceed with CPT to make DB small and efficient?

This is the info we have Bus Name Table id , bus_name 1 BUS1 2 BUS2 3 BUS3 Stop Name Table id, stop_name 1 STOP1 2 STOP2 3 STOP3 4 STOP4 5 STOP5 Route ...
1
vote
0answers
51 views

More then one menu items are assigned with “current-menu-item” class

I am new with WordPress so apologize if i am doing this in a wrong way. I have lot of taxonomies and posts types. I am using one term (from any of the taxonomy) in more then one places in my menu but ...
1
vote
0answers
29 views

Blog posts repeat

Good Afternoon! I have having an issue on a site I am working on where in that the blog posts "repeat" and by that I mean they are being displayed twice. Ideally I would like the page to work as ...