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,301
questions
0
votes
0
answers
14
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
41
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
155
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
27
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
21
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
151
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 $...
2
votes
1
answer
1k
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
22
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
17
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
283
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
57
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
17
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
56
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
21
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
52
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
46
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
88
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( ...
0
votes
0
answers
51
views
Fetch data from two custom post types and create multidimensional array for output to html table
I have two CPT (brochures and brochures_so). In both CPT i use ACF field (key = jaar)
brochures
Jaar (ACF field)
Vakgebied (Custom taxonomy)
2021
Wiskunde
2022
PAV
2022
Frans
brochures_so
Jaar (...
1
vote
0
answers
295
views
Compare ACF date field (if exists) and post date and order DESC
I have an ACF date field (same format as post date) and in my Query I want it to be compared to the publish date of the post:
If erstelldatum is not empty use erstelldatum for order
If erstelldatum ...
0
votes
1
answer
382
views
Display category name of custom posts only once in the loop
I have a custom post type called "Projects" and for it some categories.
I would like to display the category name of the posts in the loop but only once.
I am using this but the category is ...
0
votes
0
answers
147
views
get_the_terms() returning wrong results inside of loop
When I use get_the_terms() inside a loop, the whole thing behaves very strangely. Sometimes the terms are included twice or three times and sometimes a post inside of the loop returns only false.
I ...
0
votes
2
answers
40
views
Forcing page to top of the list when using get_pages
I am using get_pages to pull the children pages from a parent and listing them in a similar way to the standard WP loop for pages. This works well using the code referenced below - however.. what I ...
0
votes
1
answer
16
views
Add leading zero to current post display [closed]
I am using the next to show in a loop of posts the current post and the total of posts published.
$post_query = new WP_Query($args);
$postAmount = wp_count_posts( 'post' )->publish;
<?php echo ...
1
vote
1
answer
102
views
Filter post by current 2 differents users id
I'm filtering my custom post type based on author. I want all users to be able to:
1 - in the list everyone can see the posts created by the admin.
2 - users can also see their own posts in the list, ...
0
votes
1
answer
63
views
ACF to select posts not displaying on blog page
I am trying to implement a repeater / post object so I can select posts that I want to displaying on the sidebar. I am using this code:
<?php while ( have_rows('top_posts_repeater')) : the_row(); /...
0
votes
1
answer
32
views
For each loop on every word in post
I'm having a recipe site where every post naturally contains ingredients. Every ingredient is a tag, and I would like to automatically link every ingredient so the user can click on it and see all ...
0
votes
1
answer
74
views
Dynamically insert code to custom post type loop
I need to display post from custom post type name "film", from a specific taxonomy "Horror."
Everything work fine when I type the taxonomy directly like this:
<?php $blog = ...
0
votes
0
answers
21
views
Sort posts according to a numeric value entered with ACF
I've tried a little bit of everything, but I still can't find the right solution.
I need to sort my posts according to a numeric value that is entered in each post. I'm using the following PHP code, ...
0
votes
0
answers
21
views
Custom Header added within Dashboard pages, is this possible with custom template files?
I created a custom template and called it Header Home"header-home.php"
<?php
/**
* Template Name: Header Home
*/
?>
<?php
if( have_post() ) {
while( have_post() ){
...
0
votes
1
answer
103
views
Custom Fields - How to create a list from multi-line entries of a single value
If I have the following name/value pair for a custom field....
...is there a PHP loop process I can apply that will allow me to display them on the front-end as individual values because there is a ...
0
votes
1
answer
267
views
Category post count is not correct
When I go to Posts > Categories, some categories show that they have a post. See screenshot. But there are no posts linked to that category. When you click on that "1"-number, no posts ...
1
vote
1
answer
48
views
WordPress Loop inside Loop?
I'm using ACF, and displaying the Brands CPT. Inside of brands, I will want to setup a separate loop for posts containing certain tags.
My loop works, meaning that I'm able to access the brands and ...
0
votes
1
answer
29
views
List page is showing 404
I have built a new site based on a content from an old one. Also, there is some partial content in another WordPress blog which I have to import. Unfortunately, on the blog I don't have full access, ...
0
votes
1
answer
41
views
Include current post into loop
I have a related posts loop ( in every single post page ) based on post title. source : https://wpza.net/get-related-posts-based-on-the-posts-content-in-wordpress/
But I also need to include current ...
0
votes
0
answers
15
views
How do I set the Stewart Search Template to return only published posts in the result
I recently took a WP.com online webinar and the moderator referred me here to ask my question. I am trying to redesign my site using FSE. I am using the "Stewart" theme.
I have added a ...
0
votes
1
answer
390
views
Use callback function in AJAX pure javascript [closed]
I've been looking for a while, but nothing answers my question.
How can I turn this code in jQuery into pure javascript?
I need it to work for the load more that loads other posts on my WordPress site....
0
votes
1
answer
170
views
Custom archive page for custom taxonomy and pagination issue
so this is something I am trying to figure out for quite some time about my custom archive page for a custom taxonomy 'workplace'. There is many workplaces, and what i want is to display the products (...
0
votes
0
answers
303
views
Function the_posts_pagination() not compatible with WP_Query arguments
I trying to make a list with posts from specific category. It's supposed to work as the loop in category.php file. Unfortunately i have problem with pagination links which are completely not ...
0
votes
1
answer
108
views
Custom loop ordering not working
I have a custom loop to display the children of a parent page which works well - however, I cant get the ordering of the items to work as I want - I want them to appear in alphabetical order (A>Z). ...
0
votes
1
answer
596
views
Properly loop through and paginate page on each function call
Alright, I need some help and I don't know if I'm doing it the correct way, but I wanted to see if the community can guide me in a better direction.
Here is what's going on:
I have a ...
0
votes
1
answer
157
views
Add custom text automatically on each post
Suppose I have a post and it's the first paragraph is:
"This a Pen. The color is red."
I want to add a custom text like "2022" after "Pen" on first sentence, at the end ...
1
vote
0
answers
20
views
Sort by alphabetical order archive.php page
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post();
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
?&...
1
vote
0
answers
57
views
Getting different functions data while using while loop in wordpress
I have added this code in the function.php file but when I use while loop in any other files this function is getting triggered.
<?php
add_action('loop_start', 'userlogin');
function userlogin()
{
...
0
votes
0
answers
11
views
CPT loop doesn't seem to account for post date?
I have some custom post types called "products", all with different published dates. Below is my loop that grabs these posts:
$args = array(
'post_type' => 'product',
'...
1
vote
1
answer
63
views
Class active for Archive link - looped out
I want to have the current Archive page link to have the class "selected". So if I'm in /category/featured/ that button on the menu should have the class selected.
After trying several ...
0
votes
0
answers
99
views
How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
I have an ACF text field for a CPT that is holding a date in DD/MM/YYYY format (it's a text field and not a datepicker field as the data was imported from a CSV file).
My Wordpress loop then sorts by ...
0
votes
1
answer
254
views
ACF flexible content block not showing on live site (works locally)
I've made a flexible content section in ACF for a specific category that allows the user to post text and different image galleries onto their post. This all works perfectly whilst I'm on my ...