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
1 answer
16 views

Split have_posts() by two columns [closed]

I need to divide into 2 columns this loop. For example, 4 elements will go the left column, and the remaining 3-4 will go to the right column. <?php global $wp_query; $args = array(...
user avatar
0 votes
0 answers
8 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 ...
user avatar
0 votes
1 answer
28 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 $...
user avatar
1 vote
1 answer
50 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 ...
user avatar
  • 111
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(...
user avatar
0 votes
0 answers
14 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 ...
user avatar
1 vote
1 answer
169 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 ...
user avatar
0 votes
1 answer
13 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 ...
user avatar
0 votes
1 answer
11 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 ( $...
user avatar
  • 11
0 votes
0 answers
25 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' =&...
user avatar
0 votes
1 answer
21 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 ...
user avatar
0 votes
1 answer
14 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 ...
user avatar
  • 193
0 votes
0 answers
33 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 ...
user avatar
  • 1
1 vote
0 answers
22 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 ...
user avatar
  • 11
0 votes
1 answer
82 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( ...
user avatar
  • 53
0 votes
0 answers
16 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 (...
user avatar
  • 101
0 votes
0 answers
60 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 ...
user avatar
0 votes
1 answer
30 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 ...
user avatar
  • 1
0 votes
0 answers
72 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 ...
user avatar
  • 41
0 votes
2 answers
31 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 ...
user avatar
  • 101
0 votes
1 answer
14 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 ...
user avatar
  • 19
1 vote
1 answer
34 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, ...
user avatar
0 votes
1 answer
18 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(); /...
user avatar
0 votes
1 answer
31 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 ...
user avatar
0 votes
1 answer
28 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 = ...
user avatar
0 votes
0 answers
14 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, ...
user avatar
0 votes
0 answers
20 views

How to loop specific Category menu from archive page?

I'm trying to loop a specific product category menu from the archive.php page and the category has 4 columns or as a 4th Tree How I can Loop it here in ul ? <ul><!-- 1--> <li&...
user avatar
0 votes
0 answers
16 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() ){ ...
user avatar
0 votes
1 answer
37 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 ...
user avatar
  • 718
0 votes
1 answer
35 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 ...
user avatar
  • 125
0 votes
0 answers
17 views

Display all categories but only if they have posts in them that have a specific tag assigned

I have a WooCommerce site and am working on the product tag pages. I want to display every product that is assigned to that tag, and break them up into their individual categories (this bit is working)...
user avatar
0 votes
0 answers
18 views

Woocommerce Variable Product Dropdown for Custom Shop Template

I'm building out a custom shop template and I'm trying to achieve something like this. Where the user can choose the product variation in the dropdown, choose quantity, and click add to cart without ...
user avatar
0 votes
0 answers
26 views

Get Posts List of Current Selected Custom Taxonomy in Shortcode

I have a custom taxonomy called Album Link (album_link). I created this so I could link all music that has the term e.g (Glorious Album) to an album post type that uses the same term. The goal here is ...
user avatar
1 vote
1 answer
33 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 ...
user avatar
0 votes
1 answer
25 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, ...
user avatar
  • 101
0 votes
0 answers
25 views

What am I missing in this Code Block?

I am using ACF Pro and Oxygen Builder. I have a FG (Repeater) set for a Rooms & Suites FG. I have several sub_fields to capture attributes of each such hotel room that gets created via its CPT. ...
user avatar
0 votes
1 answer
21 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 ...
user avatar
0 votes
0 answers
12 views

Page that lists publications by classifying them by taxonomy

I need a little help writing code. I have an "artists" CPT I have an archive-artists.php page with the code below, but I would need to add a "year" taxonomy. And that my artist ...
user avatar
0 votes
0 answers
12 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 ...
user avatar
  • 1
-1 votes
1 answer
117 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....
user avatar
0 votes
1 answer
39 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 (...
user avatar
  • 16
0 votes
0 answers
83 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 ...
user avatar
  • 145
0 votes
1 answer
21 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). ...
user avatar
  • 3
0 votes
1 answer
196 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 ...
user avatar
  • 21
0 votes
1 answer
68 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 ...
user avatar
1 vote
0 answers
18 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' ); ?&...
user avatar
  • 11
0 votes
0 answers
16 views

Include last post date in get_categories loop

I have a simple get_categories loop on a template page which works fine to display a list of categories within the parent category 52 (as shown below). I would like to also display the last post date ...
user avatar
  • 1
1 vote
0 answers
32 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() { ...
user avatar
  • 9
0 votes
0 answers
9 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', '...
user avatar
  • 101
1 vote
1 answer
22 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 ...
user avatar
  • 13

1
2 3 4 5
66