Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
12 views

Show post first in loop based upon meta key, in array of multiple categories

I am trying to achieve the following. Using the wordpress theme newspaper, a custom block is displaying the four most recent posts from a couple of categories, which are set in a tagdiv composer that ...
0
votes
2answers
21 views

Include future posts in tags and in search

I am using something like this to query and display future or scheduled posts on my homepage: <?php query_posts('post_status=future&posts_per_page=10&order=ASC'); while ( have_posts() ) : ...
1
vote
0answers
16 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,...
0
votes
0answers
20 views

how to get custom attachment url?

Is there a common method to get a custom attachment URL regardless of the plugin or custom code used? Say if I use ACF plugin I can create an image field and get the url with get_field('fieldname'); ...
0
votes
0answers
10 views

Substitute post with certain meta key in loop

I have some logic where a post can be a link to another object. And if it outputted on frontend linked post should be shown, not original. Now I have the following code in my template: $is_list_link =...
0
votes
1answer
23 views

How to distinguish pages created by woocommerce?

I am working on a theme and I have come to a situation when I need to distinguish the pages that are created by the Woocommerce plugin (e.g Shop, Cart, etc.). So far I've installed this plugin which ...
0
votes
1answer
26 views

List posts that don't have a specific tag?

I am trying to list posts that do NOT have specific tags. Currently, I am looping through each tag in a post, and if it's doesn't exist, list it. This works, except that it will list the same URL ...
0
votes
1answer
16 views

Pass post ID from archive template to functions file

I have an archive template where I am displaying a "featured post" at the top of the page. I am building my post loop for the rest of the page in the functions.php file. What I would like to do is get ...
1
vote
1answer
29 views

get author_name from queried post

All I'm trying to do is, get the author name of the current post and set it's name as a tag. I tried changing author_id to author_name but didn't really get anything back. wp_set_post_tags should ...
0
votes
2answers
79 views

use loop to return blog details

I want to return information about a blog. It could be, author name, title, date, country whatever just to test. <?php $post_id = get_the_ID(); while ($post_id != 0) { ...
-1
votes
1answer
15 views

Help with showing text when something is entered in my search bar

I'm having troubles replacing text when there is something entered in the search form. As you can see in the image below i want to replace 'mijn gemeente' with the get_search_query text if i'm ...
1
vote
0answers
22 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
14 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 ...
0
votes
0answers
15 views

Filter and Display posts by layout

I have structure: navigation: <div class="blog__category" > <ul class=""> <?php $terms = get_terms( 'category', array( '...
0
votes
2answers
132 views

WP Query post__in not returning correct results

At the bottom of my page I am trying to display some recent projects based on a pre-selected list of post IDs. I have built a custom query to try and retrieve the 3 specific posts (WHERE ...
-1
votes
1answer
38 views

Problem with ms-thumb-frame-selected class in Master Slider

I'm using Master Slider to provide a slideshow. Inside a loop I've put some CSS to make the class .ms-thumb-frame-selected to dynamically use the thumb of a post as background. But now my problem is ...
0
votes
2answers
45 views

How to output values from a loop into a javascript array

I'm building a custom shortcode in Wordpress. Essentially what I want this to do is the following: Dynamically pull values from a group of Advanced Custom Fields Output those values into a javascript ...
0
votes
0answers
18 views

Ajax buttons not working properly in WooCommerce when using wc_get_template_part

I have a custom loop on my website home page of best selling products. I am using wc_get_template_part('content', 'product'); to pull in the products. But when I click the buy button, the buy button ...
0
votes
0answers
12 views

Get chars after last , (comma) country [migrated]

I want to get last chance of comma (,) in a $country. But how do I do it? foreach ($countries as $country) { $country_id = $country['ID']; $country = get_the_title().", "; //comma echo "<...
-1
votes
1answer
30 views

First post in loop displays twice

I have created a wp_query where I change the post format after every 4th post. Unfortunately, the first post is displaying twice which is surely something wrong with my modulo conditions. I appreciate ...
1
vote
2answers
37 views

Using Javascript for Looped Content

I have set up a loop to pull in staff bios. When a user clicks on the thumbnail of the staff member a popup with the complete bio information for that "post" should be displayed. I have been able to ...
0
votes
1answer
23 views

Get first URL from post content

Basically all I want to do is if the post format is "link" rather than link to the post from the blog index, link to the link pasted within the post content. In my index.php I have: <h3> <...
0
votes
1answer
45 views

AJAX Breaking Offset Argument In WP Query

I have been using AJAX on my website successfully and for my category.php page I need to use the offset argument. Unfortunately, AJAX creates complications with offset and I get the same posts looping ...
0
votes
1answer
18 views

How can I use WP_Query to sort 'event' custom post type by date?

I have a custom query that in another iteration I'm using to only display events in the future: $today = date('Ymd'); if ( is_post_type_archive('event')) { $eventPosts = new WP_Query(array( ...
0
votes
2answers
28 views

How to get_posts where 'menu_order' is more than 0/zero?

Is it possible to get posts where menu_order is more than 0? I have tried this argument when I get_posts() but it doesn't have any effect at all: 'meta_query' => array( 'key' => '...
1
vote
1answer
7 views

Custom post type appearing within the previous one on archive.php

This is my first custom theme so I'm still getting my head around the loop, but I've somehow got each successive post to appear around the previous one. I'm using bootstrap cards so the border for ...
1
vote
2answers
25 views

Displaying Woocommerce Product Category in Wordpress

I'm trying to create a custom theme. I added theme compatibility with Woocommerce to my theme, and am trying to create a product loop. I want to filter my loop so it only displays post with the ...
0
votes
2answers
64 views

Way to display “Yesterday”, “Today”

I currently use the following code below in my loop to display dates for groups of posts. Works great, was just wondering if it's possible to change the day from php code 'l'(Sunday-Saturday) to Today ...
0
votes
2answers
22 views

WordPress Ajax filter: Create two loops for different output styles?

I have two different pages, with filters. Those two pages, have different layouts and styles. I have three different filters for one page, where the output and style is the same. For the “newsfilter”...
0
votes
1answer
33 views

Loop doesn't show title of second post and posts thereafter

I have a problem with my code, somehow. It worked fine before and now it seems that Wordpress does not show the title of the second blog posts (only the first blog post seems to work fine really, ...
0
votes
1answer
21 views

How to display sticky post always at the top (before regular post) in wordpress?

I am working on a wordpress code as shown below in which the modified post displays at the top. $temp_args = [ 'post_type' => array('current-channel', 'post', 'current-episodes'), '...
0
votes
2answers
33 views

WP_QUERY wrong ammount of posts

I have 16 published posts of type "portfolio". With the query below, "found_posts" is 16. Correct so far. I've set "posts_per_page" to -1 to see all of them. But only 8 of them get rendered. The ...
0
votes
0answers
30 views

How to display list of most popular posts from custom post type

I have a custom post type for articles with a custom taxonomy for topics. I wanted to keep this separate from the standard Wordpress blog (posts) which is why I created this. I want to show the 3 ...
0
votes
1answer
16 views

How to add a lightbox to class mix?

I have a question: how to add a lightbox to a photo. I've been sitting here a bit and I can not deal with it. <?php //Dynamic Portfolio With Shortcode function portfolio_shortcode($atts){ ...
0
votes
2answers
16 views

adding or removing endforeach; throws error!

This is my code, where i keep getting either error: unexpected endforeach; if endforeach is used or unexpected end of file if i don't use endforeach; It's driving me crazy!! <ul id="portfolio-...
0
votes
1answer
32 views

post_type incorrect for custom post type

I am trying to display a different template depending on the post type. I have registered two custom post types called resource and contact. When I try to get the post type in search.php (using ...
0
votes
0answers
33 views

Loop (for search results) returning right posts, but wrong post type

Hoping this isn't already asked/answered, but it's a tough one to search. I've got a site based on the Flatsome theme which uses custom post types (through various plugins). The search page works in ...
0
votes
0answers
20 views

Sort custom post type by other custom post type field. (Places by their reviews mean vote)

I'm trying to sort Places (first custom post) by its Reviews (second custom post) average (mean) vote. So, basically I have two custom post types, one is Places and the other one is Reviews. Reviews ...
0
votes
1answer
39 views

How to add sort order to incremented and paginated category loop

I used this in a loop on a category template to get a numbered lists of posts that continues in the next page: <?php $mypage = (get_query_var('paged')) ? get_query_var('paged') : 1; $ppp = ...
0
votes
2answers
29 views

Skip latest 3 posts from loop

I downloaded a starter theme (Underscores). I want to exclude first 3 post from my loop on index page. Here is the loop; <?php if ( have_posts() ) : if ( is_home() && ! is_front_page()...
0
votes
1answer
31 views

Get post meta value outside of the loop

I'm working on an extra function to list different stuff, My function looks like: "display all hotels for a specific city" -> hotels is as CPT and CITY as custom Tax. So for exemple, lets display ...
1
vote
2answers
116 views

This AJAX Code Doesn't Work - Looking for elegant solution

I am trying to utilize AJAX on my WordPress site for posts as a user scrolls. I followed this tutorial but it has no effect on my WordPress website. I have used a plugin that works, but I'd much ...
0
votes
0answers
14 views

Wordpress - Get 2nd level child categories while looping 1st level child categories

I'm trying to loop and get the 1st and 2nd depth child categories of the 'Parent Cat 3' which has the id of '17'. Here's a simplified form of my category structure PARENT CAT 1 PARENT CAT 2 PARENT ...
0
votes
1answer
29 views

Query post with content only

I need to loop through the last 3 posts movie, but only those which have a content not empty. I used to do as follow when I used the ACF editor instead of the native one. movie-content refers to ...
0
votes
1answer
103 views

get_next_post() and get_previous_post() return wrong posts

I’ve been trying to retrieve the next and previous post in one of my Wordpress templates. Please note that I want to get the full post object instead of just the pre-formatted links to the posts. The ...
0
votes
1answer
35 views

Moved a website and excerpts don't work for old posts

I moved a WordPress website to a different host and all post excerpts stopped working in the blog list. When I make a new post they appear fine but doesn't show for the old posts. I peaked into the ...
0
votes
1answer
47 views

Pagination for a cpt filtered with a category

I was tasked with creating a posts aggregator that fits seamlessly into the category nav-bar. For this to work, I could not use the category-list.php that exists, for it is full of workarounds and ...
0
votes
1answer
11 views

Prevent function from triggering on current page

I created a list of posts, each post about a car model. After that, I created a post about the best car models. This post grabs each post about every car model and displays them in a snippet list ...
0
votes
0answers
24 views

Problem with my loops

I am French. Sorry if i make mistakes. I have two problems. The first, I have a page that shows all paying activities sort by date. The 'posts_per_page' does not work When I put 10, it shows 8 ...
0
votes
1answer
27 views

Bootstrap tabs are not being clicked in WordPress loop

I am trying to show some Bootstrap tab contents within a WordPress loop. The tabs are not being clicked. Here are the bootstrap codes: <ul class="citenav nav nav-tabs" id="myTab" role="...