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.

Filter by
Sorted by
Tagged with
0
votes
0answers
7 views

Post shows up in database, not in dashboard, screws up other posts in the loop

I'm pretty new to Wordpress developement and I'm really not sure what's happening here. I've created a new category called "Advertorial" and my goal was to loop thorugh it with a WP_query ...
0
votes
0answers
6 views

using custom paged variable in get_previous_posts_link() function

Is there any way to use a custom paged variable in get_previous_posts_link function? I have two different custom loop on one page and need to have two different and independent pagination for these ...
0
votes
0answers
17 views

Create a page template for “top rated posts” but show full content and not just a list

Sorry upfront if I'm not explaining this clearly. I'm using WP-PostRatings and it has this function: <?php if (function_exists('get_most_rated')): ?> <ul> <?php ...
0
votes
0answers
14 views

how to display the image on the category page wordpress?

this is code upload image & edit image category https://pastebin.com/GmjsJ2K7 this is code for loop category with image <?php foreach ($tax_terms as $tax_term) { ...
0
votes
0answers
11 views

how to make my custom gallery work in wordpress

So am creating a custom theme in WordPress and looking to achieve this I was able to output my category but not too sure how to output the remaining information. As you can see from the image below ...
0
votes
0answers
8 views

How do I write a loop to get and display product list by tag, place in a function and add shortcode to page within admin?

How do I write a loop that gets and displays a product list by tag, place in a function and add shortcode to page within admin so I can display that lsit where i'd like? I have no code :(
0
votes
0answers
21 views

audio auto play not work in wordpress

<audio controls autoplay> <source src="horse.ogg" type="audio/ogg"> <source src="horse.mp3" type="audio/mpeg"> Your browser does not ...
0
votes
0answers
13 views

Is there anyway I can call the year once?

Hi everyone I hope you have a great day, I was wondering if is there anyway I can call the year once?. I really don't know if its possible to call the date once cause mine keeps on repeating calling ...
0
votes
3answers
17 views

Having issue with Wordpress loop

I am learning about WordPress development. I ran into an issue but could not figure out what am I doing wrong I want to show all of the posts on a page using a custom template. I am following this ...
0
votes
2answers
29 views

get_comments with post_status 'public' retrieves NULL result

This is my loop: <?php $comments = get_comments(array( 'status' => 'approve', 'type' => 'comment', 'number' => 10, 'post_status' => 'public' )); ?> <ul class=&...
1
vote
0answers
17 views

How to show user online status on their posts?

I've tried a lot to solve this but of no use. I have a classified wordpress website where users can post their ads. I want to show their online status on the ad they post (archive and single posts as ...
0
votes
0answers
9 views

Wordpress Next Post and Previous Post with Custom Post Type UI

I am trying to add the "Next Post" and "Previous Post" but I don't know how to pull the posts from my portfolio item which I created in the plugin CUSTOM POST TYPE UI. Please see ...
0
votes
0answers
11 views

Save a loop of single meta box data from selected dropdown lists

The layout of my edit post page I have 193 countries in Afghanistan post and in every single post "passport". I want add post meta data for "Visa Status" for each country of the ...
0
votes
0answers
9 views

Add repeater field data to only selected post

I have a wp_query with the while loop, I added a form for each post when I submit the form data it submits to other posts as well instead of submitting to the current selected post. <?php $query = ...
0
votes
0answers
9 views

All posts in TCPDF

I need use TCPDF for my site and then get all posts with images, content, titles in PDF document, i have code: function output_pdf() { $posts = get_posts( 'posts_per_page=-1' ); ...
0
votes
0answers
14 views

How To Add Banner Ads Between Posts With Wordpress/Kadence/Ads Inserter

I have a website that currently inserts banner ads on the front of my woocommerce website after the 6th product (between rows 2 and 3) and after the 12th product (between rows 4 and 5). This location ...
0
votes
0answers
18 views

How to exclude child categories from multiple parents in WP_Query?

I have some code <?php $exclude_category = [10]; $company_category_parents = get_categories( array('child_of' => 5) ); foreach ($company_category_parents as $...
1
vote
1answer
34 views

Slow WP_query due to nested wp_query. Need Suggestions

I'm facing an issue of slow queries. As I'm not that familiar with the WP_query, I managed to solve my problem with nested wp_query. https://it.zoetalentsolutions.com/technology-provider/aws/ in the ...
0
votes
1answer
18 views

Do not show sub categories in the loop on archive-product.php

Currently, the site I am working on uses archive-product.php to load the Woocommerce product loop and with it, load the content-product.php template part. However, in my loop, if there are ...
0
votes
1answer
22 views

Database query and get_user_meta return incorrect data

I have a PHP script that gets details from a checkbox and a text field. The console.log data is correct and so is the updated data in the database, however, when I try and get the data, using $wpdb or ...
0
votes
0answers
12 views

Modify the loop template in a plugin

Is it possible to modify the output of a loop template from a plugin without using template_include to define a whole new template. My goal is to only modify the loop's output so that the plugin won't ...
0
votes
1answer
107 views

Pagination Not Working When Used With WP_Query() `offset` Property

I have an archive page that pulls in posts using WP_Query(). On the homepage of the site it shows 16 of the custom post type posts, so on the archive I offset the archive page by 16 posts. The code ...
0
votes
1answer
17 views

php loop error for count posts in category

I have multiple categories on my wordpress page and each of the categories has 1 to n subcategories. If a subcategory contains only 1 single post I would love to display an excerpt of this post, ...
0
votes
1answer
31 views

issue with if/elseif in_array inside foreach loop display only one post

I try to attribute a specific background-color to each post if one of categories of post corresponding to one category. My function works but is restricted to display only one post in result. If I ...
1
vote
1answer
25 views

Styling text and images in the_content()

So I have recently started working on Wordpress and coming from a different programming background, having the logic but not being able to actually code is an issue I have been butting my head on for ...
1
vote
0answers
17 views

Displaying CPT and custom taxonomy side by side in Bootstrap 4 component

I'm trying to reproduce a bootstrap navigation component inside a page that display sub category and associated posts to those sub-categories like this: Taxonomy term 1 taxonomy sub-term 1 Post 1 ...
0
votes
1answer
21 views

when looping through custom post data not appearing

i have a loop that fetch custom post type from the database now when i go to the page the data doesnt appear but when i refresh the page 2 times the data shows here is the code: <div class=&...
0
votes
2answers
28 views

Can I alter the main loop to 'orderby' a custom callback?

I have a custom post type where the title is a name, and I want to sort the loop by the last word in title, the surname. I can easily break the names apart and filter by the last word in a custom ...
0
votes
0answers
13 views

Woocommerce add and show star ratings

I want to show the rating stars on 2 places on my woocommerce website: In the custom product loop And the single product page I've added do_action('woocommerce_template_loop_rating'); in the product ...
3
votes
1answer
55 views

When and Why is is_singular('my_cpt') true while in_the_loop() is false?

I'm using example code for a templating system. Page at this address: http://project.test/my_cpt/hello-post/. Cannot understand why is_singular( 'my_cpt' ) is true while in_the_loop() is false. Within ...
0
votes
1answer
32 views

How to implement template file and the loop

I am trying to understand how to use a custom template file, in this case simply to list all posts. Based on my research, and initial responses to this post, the code looks like this: <?php /** *...
0
votes
1answer
18 views

Why does the first loop take arguments from the second loop?

I created an index.php file with two loops. The first one is standard and should only show the title of the page. Just below it is the second loop with class WP_Query. My problem is that the first ...
0
votes
0answers
12 views

Loop through Previous/Next Posts

I'm wondering if there's a way to, starting at the current post, loop backwards or forwards through all previous or next posts in a given taxonomy, and do something on each iteration. I'd then like ...
0
votes
0answers
26 views

How to avoid duplicate posts queried from custom meta?

I'm querying custom posts taken from a custom metabox where you pick which posts to display to be used as criteria for filtering. How do I avoid duplicates? Current code (displays all authors - the ...
0
votes
0answers
10 views

display post pdf attachments in side bar with link text

I have a widget that places links to pdf attachments in the sidebar. I want to use the pdf attachment text heading (that is used to display it in the parent post) as the title. I cannot get this to ...
0
votes
0answers
20 views

Order posts alphabetically with numbers but some of the posts has numbers in the title

I have this query: $args = array( 'post_type' => 'alerts', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'post_title', 'order' => 'ASC', ); ...
0
votes
1answer
13 views

How to display fields from the loop in two separate divs

I'm making this website where i'm displaying things in two colums: on the left, a list of titles, when you click them, it expands a text and on the right it show the corresponding images. To do so, I ...
0
votes
0answers
55 views

Code to Update Prices and add them for Woocommerce Custom Product Variations Loop

I am actually struggling with some custom functions. Actually My aim is the following: Create 2 custom fields in a woocommerce variable product backend ✔ Show these custom fields text and prices in ...
0
votes
0answers
31 views

Loop only shows first two posts

this team section. loop through team members. it just shows the first two members. whatever I added after the first two members, do not appear. so what the wrong here, please? <section id="our-...
2
votes
1answer
38 views

How do you output custom code between posts in the loop?

I am trying to put a header before past posts and after future posts. I'm using get_posts() in a function to output the posts using a foreach loop for a custom post type ordered by date (meta key). If ...
0
votes
0answers
25 views

Create pagination foreach loop

I have this foreach loop on a page how can I create pagination links for posts $args = array( 'numberposts' => 4, ); $catPosts = get_posts( $args ); foreach( $catPosts as $...
0
votes
1answer
21 views

First x post with another template then the others

I want to output the 5 latest posts. But the template of the first 2 must be different than the other 3 posts. So I've created two queries. The first one shows the 2 posts: <?php $loop = new ...
0
votes
1answer
17 views

Why is my archive page looping through all but one post?

I've created an archive page for my custom posts, it loops through every one except the first. There is 11 posts overall and I only get 10 on the archive page. Here is my archive template: <div ...
0
votes
0answers
34 views

How To Displays Sub Category Posts on The Parent Category Page?

I have one parent category underneath, there are two sub categories. Prent Category: Windows: example.com/windows/ Sub Category: Multimedia: example.com/windows/multimedia/ Browsers: example.com/...
1
vote
1answer
43 views

How to get an array of years from all of the search results, and use it to filter by year the paginated loop?

I hope this is not too dumb: even though I'm learning at an acceptable rate, my WP knowledge still has some important gaps. What do I have: My search.php template gets its results from the normal ...
0
votes
1answer
21 views

Display all categories including sub categories under a list ul

This code is displaying only categories, how can I change to also include subcategories. Thanks Thanks, with this code is listing all together, I want that shows like this Category 1 ...
0
votes
0answers
27 views

Get posts that are parents which don't have any children with WP_Query

I have a hierarchical custom post type which has posts with no children and also posts that have one or multiple direct children (only up to a depth of 1, i.e no children of children). For example: ...
0
votes
1answer
44 views

How to add automatically bootstrap 4 order-lg-1 and order-lg-2 classes for columns in foreach loop based on the count?

How to add automatically bootstrap 4 order-lg-1 and order-lg-2 classes for columns in foreach loop based on the count? PHP and Html Code <?php //get your custom posts ids as an array $...
0
votes
0answers
18 views

Template category.php with page (no posts)

on my home page I have clickable images that redirect me to custom pages. On each page, I've made sure I can assign categories. Now, I want to filter these categories by clicking on the button ...
0
votes
2answers
37 views

has_excerpt() not working inside wp_query

I am trying to check for an excerpt and if it doesn't exist then show the content but trimmed. Currently nothing is showing. <?php if (has_excerpt() ): ?> <p><?php echo ...

1
2 3 4 5
63