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.
3,291
questions
1
vote
1
answer
18
views
Complex Custom Loop with Includes
The Problem
I have a complex loop designed for showcasing my portfolio.
Here is the criteria:
Portfolio is powered by a custom post type called PORTFOLIO
Each post will be assigned a class of either '...
0
votes
0
answers
11
views
I make sticky post for my archive page for custom post type with ACF field and loop is not working
I make sticky post for my archive page for custom post type with ACF field and loop is not working
while($query->have_posts() ){
$query->the_post();
$sticky = get_field('...
0
votes
2
answers
30
views
I want to show image from custom field image on my custom page template
I have created a taxonomy and in that taxonomy i have created custom field for image. Now I want to show that custom field image on my custom page template with category name. I have tried much it is ...
1
vote
0
answers
41
views
WordPress Ajax load doesn't work
Hello I have set up custom Ajax load more without plugins, but it’s only showing 3 posts on home page, and when clicking on button to load more it’s not loading anything. As I am a beginner I am ...
0
votes
0
answers
21
views
Page with redirect
I have an issue with indexing my website, where I get "Page with redirect" error on GSC or " Redirect loop", also on Yandex ( Yandex says The rel="canonical" attribute in ...
0
votes
1
answer
26
views
Custom WordPress loop, articles not in same order as Array
I'm working on a news website that has a top section with eight featured articles. I use ACF fields for these featured articles and input their ID.
This is how the loop looks:
$kiemelt1 = get_field('...
0
votes
1
answer
31
views
How to insert a post from a different post type after every nth post
The idea seems simple enough, insert a post from a different post type after every 3rd post in a wp_query. So should look something like this:
Article 1
Article 2
Article 3
Ad 1
Article 4
Article 5
...
0
votes
0
answers
24
views
Update post meta with wp cron
I am trying to create a function (which I will trigger through the WP Cron) but no values are passed and the database values remain NULL. Could anyone point me in the right direction of where I'm ...
-1
votes
1
answer
21
views
wp_mail function not working in user query loop
I'm trying to send an e-mail to every user who is logged in more than a year ago (based on woocommerce meta value from database), but the e-mails do not go out. In my code I'm trying to filter myself ...
-1
votes
1
answer
23
views
Show number of posts AND number on current page (cannot make it work)
I have looked over the following but still cannot make this work;
Show number of posts AND number on current page
Show number of posts and number on current page (revisited)
This is what I currently ...
0
votes
1
answer
45
views
Custom Wp_query loop takes very long
I've got a simple custom WP_Query on a custom post type page that shows a collection of posts:
$t_query = new WP_Query($filters['filtered_args_for_query']);
$wpdb->last_query outputs:
SELECT ...
0
votes
0
answers
56
views
Two loops in CPT archive page, exclude posts from main query
I have two loops in my archive-inzerat.php, first is custom loop, second is default loop:
<div class="container">
<div class="row">
<?php
...
0
votes
1
answer
29
views
How to print different informations for different post types inside The Loop?
I have a homepage that is mixing two post-types : post and events
My aim is to print the details of each event in order to differentiate the content.
This is the method that I used to mix posts and ...
0
votes
1
answer
19
views
Insert multiple custom components after x-number of posts
While there are many posted solutions on how to insert custom components between posts, I haven't been able to find one that addresses pagination. Currently, on my Wordpress archive template, each ...
0
votes
0
answers
11
views
Hide old posts each year
I've had an interesting enquiry from a client site we built (using Extra theme from Elegant Themes) and manage for a school. Each early September, when the school starts a new academic year, they ...
0
votes
0
answers
28
views
Get full slug for a Wordpress Post
I am using this code to get the URL of a post which is subsequently used as input on a form field.
global $post;$post_slug = $post->post_name;$post_slug = urlencode($post_slug);
However, this ...
0
votes
0
answers
9
views
How to display content depending on the Woocommerce Product Category
I have a single product template design where there are two "sections" whose content will change according to it's product category. My plan is to create an "Elementor Section Template&...
0
votes
0
answers
19
views
Allowing null vairiable
I'm working on a shortcode to display a custom post type, which mostly works. I don't control the feed this data is coming from, hence the need to split up the title based on delimiters. The problem I'...
1
vote
1
answer
50
views
How do I split a large query with a semi-expensive function included into multiple smaller queries
I have a count stored in post-meta called version-count. I just wrote a little plugin to delete the data stored in this post-meta using delete_post_meta_by_key.
I want my plugin to then go through ...
0
votes
0
answers
14
views
WPNavi pagination links not working on custom pages
I've been googling this for awhile and can't seem to find a solution that fixes an issue I'm having:
I'm using WPNavi on a custom post type in order to display a related content section (i.e. to ...
1
vote
1
answer
17
views
Prevent duplicating specific column from database table
I have SQL table of cities and counties. I need to loop over them and create dropdown with labels. Cities should be an <option> elements and counties wrapper <optgroup>s.
function ...
0
votes
0
answers
22
views
How do I create a term for every value of a post meta?
I have some information stored in post meta that I'd like to convert to terms. I'd like to create a term in a custom taxonomy for every meta value with a particular key.
I need to loop through ALL ...
0
votes
0
answers
16
views
Filter page ID outside the loop and order
I try to create a shortcode to display a list of events (which is an ACF CPT) on other CPT pages.
In ACF the CPT "events" have a relationship field with "CFA" custom post type ...
0
votes
1
answer
56
views
How to get files from loop for zip
I am working on a button which will download the images as a zip on specific posts. It works if I leave the files array in functions.php with a few hard-coded img links. But when I move the array to ...
0
votes
0
answers
59
views
Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
I am trying to make the WooCommerce shop page display 3 products per row in the main loop only not in any other products widgets on the shop page, I want those widgets to show 4 products per row
I am ...
0
votes
0
answers
8
views
Best practice to display a list/archive of Custom Posts in a Page Template
I often need to have a Page, whose content is editable by an editor user in admin, displaying a list of Custom Posts.
So I create a Page in the admin and create a Page Template (ex : page-my_cpt.php) ...
1
vote
1
answer
35
views
Wordpress search results grouped by post type
I've been struggling to make it work. This code works and returns post_type title and post titles inside it. I found it here
But i need to have some sort of formatting and excerpt. Currently I cannot ...
0
votes
0
answers
17
views
Hook in the loop after the first post
I am trying to hook content in my wordpress loop. I'd like to insert a div after the first post.
I've found this code, that works pretty well except that it repeats the hook every 4 posts :
add_action(...
0
votes
1
answer
114
views
wp_mail sending only once inside foreach loop
I have written and re-written this code several times. I've tried removing the wp_mail function from the loop and putting it in it's own function. I've moved all the variables in to the loop. At one ...
0
votes
0
answers
13
views
How can I show posts with the same tag?
For example, I have a post titled "A" with the label x, and the other post titled "B" has the label x. I want it to be below my post titled "A" with title "B" ...
0
votes
0
answers
12
views
How home my code doesn't display any feature image? Looping through post from a taxonomy and not getting feature images back
The only thing I am trying to do is just to display each post from Services that belongs to the taxonomy called 'national' and display its title and its featured image. So far it displays each title ...
0
votes
0
answers
21
views
Prevent WordPress loop from displaying similar post titles
How can I prevent WordPress loop from displaying similar post titles?
eg.
The main post title is: Steady content
But if the array $posts_ids has a post with the title: We have some steady content, my ...
0
votes
2
answers
87
views
How to use orderby on meta_value when using Pods custom database table storage
I'm struggling to understand how I can use pre_get_post when the post's metadata is not stored in the wp_postmeta table. I use Pods (https://pods.io) to create custom post types with custom fields, ...
0
votes
0
answers
10
views
How to get post category and author name for cusmot API?
I want to get the category name and author name for custom API
function vw_blog() {
$args = [
'numberposts' => 99999,
'post_type' => 'post'
];
$posts = get_posts($...
0
votes
1
answer
24
views
Order Categories by Character Count
I'm developing a medical directory website in Wordpress, and in the Grid/List pages for the site, each of the listing cards contains a list of specialties (using the category taxonomy within the ...
0
votes
0
answers
19
views
Search AJAX Filters - Multiple Query Loops Into One Loop (Optimization)
I followed a tutorial on how to make AJAX filters and I have a concern about the loops. I am using bootstrap accordion to display the search ajax filters (ex. https://prnt.sc/gxrJE9_GocOl).
I am ...
0
votes
0
answers
10
views
On click some element i want to use some template
I have a page that calls the template, I made filters using a data-filter.These filters sort out the ALU door and PVC doors. However when I click on the pagination and goes to page 2 to list the other ...
0
votes
1
answer
86
views
Wp Query : Order by distance lat,lon
I'm new to this forum, sorry in advance :)
I have a problem with my display of my posts
Let me explain ^^
I want to perform an orderby => '$distance' and display the posts accordingly.
$lat2 and $...
1
vote
1
answer
637
views
How to filter query loop block with a search string from the query parameters
I'm running WordPress 6.0.1 and I'd like to achieve a smilingly easy thing, I have a query loop which shows posts that must be filtered by a query parameter so I can add a search box into the page.
I ...
0
votes
0
answers
16
views
Category name for all posts getting assigned to a single random post
This site shows a strange behavior where the category names for posts fetched through get_the_category() returns an empty array. However, a single random post gets the category names of all the posts(...
0
votes
0
answers
15
views
How can I loop at a Specific Taxonomy from a custom post type?
So I am stuck because I want to loop through post from a SPECIFIC taxonomy. So the Taxonomy is "State" and the post type is "Attorneys" . I have a bunch of attorneys that are in ...
1
vote
1
answer
221
views
How does WP generate the default $query in WP_Query based on the URL?
I understand the mechanisms of creating a custom query by instantiating a new WP_Query object when I need granular control of what posts I'd like to retrieve. However, after searching through the ...
0
votes
1
answer
30
views
How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
I am using ACF Pro to make a relationship between two custom post types.
One CPT is a thing and the other is a Container of Things. I need to solve the issue of things within a container of things ...
0
votes
1
answer
16
views
Problem with sorting in custom child taxonomy archive page
I have this code:
<?php
$term = get_queried_object();
$term_id = $term->term_id;
$taxonomy_name = $term->taxonomy;
$termchildren = get_term_children( $term_id, $taxonomy_name );
foreach ( $...
0
votes
0
answers
27
views
How can I do a orderby by the number of items? So basically list by starting with the array with the largest number of post
So I need a way to order it by the term with the most post on it. Is there an easy way to sort the terms like that?
$args = array('post_type' => 'attorneys',
'tax_query' =&...
0
votes
1
answer
39
views
Conditional operator OR not working with custom fields
OR operator is not working for both conditions, only check first value if true then code executed and if first is false then not check 2nd condition and return else output.
I also try with LIKE ...
0
votes
1
answer
15
views
How to Enable Ascending or Descending In WordPress Default Built-in Loop
Can someone please let me know how we can add Order functionality to WordPress Built-in Loop?
<?php
if (have_posts()) {
while (have_posts()) {
the_post();
// Post Content ...
0
votes
0
answers
43
views
get_children() Archive Template
This is my first attempt at coding & I have come unstuck with the wp_query loop integration.
I just want to build a template for a page that will check for children and list their respective ...
1
vote
0
answers
35
views
Wordpress Loop and $post
I decided to take a closer look at how WP works and ran into this question. I see that when WP is loaded, the wp() function is triggered, which will parse the request and get data from the database in ...
0
votes
1
answer
84
views
How to conditionally add Custom Post Type to Front Page
I am using the following code to show my custom post types on my front page along with the default post type:
// allows the products to show up on the main page
function add_custom_post_type_to_query( ...