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
1
vote
0answers
9 views

Iterate through posts based on array of categories

Is it possible to loop through posts based on an array of categories? I would like to loop through an array of categories and then display those posts based on the category they are a part of. Posts ...
1
vote
0answers
9 views

Group CPT posts by custom taxonomy

Being honest I've stucked with my code. So I have two things: - CPT called: opencourses - custom taxonomy called: typ currently I have a template which displays pure list of CPT posts. And it works. ...
0
votes
1answer
452 views

Excluding pages in WP_query using ACF

I have a custom loop for showing child pages of the current page, but I'd like to allow the WP user to enter page IDs to be excluded from the loop, using Advanced Custom Fields. My current loop is as ...
0
votes
1answer
526 views

Using an ACF field from a page within a post loop?

I have a page set up with custom fields using Advanced Custom Fields. One of the fields is a text field for specifying the text for a read more button. Within the page template I have a post query to ...
0
votes
1answer
1k views

Add active class to foundation 6 tabs while looping categories

I have a custom post type (bulletins) that I'm putting into Foundation 6.4.3's tabs and accordions. The taxonomies are the tab headings. The individual custom post type content is the accordions. My ...
1
vote
0answers
24 views

Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?

Short version: I am wondering if the default WP loop (for example in a rather simple index.php) is supposed to return custom posts belonging to a custom taxonomy when the URL is something like https://...
1
vote
0answers
16 views

Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?

I am trying to embed a custom WP_Query inside a shortcode I have activated on one of my pages (created in Elementor). I have a Custom Post Type called 'inspector-profiles', and for some reason when I ...
2
votes
1answer
452 views

Double count view in archive.php

I'm having a hard time using this snippet I'm getting double views each time the post is queried. This is in my functions.php file: function getPostViews($postID){ $count_key = 'post_views_count';...
1
vote
1answer
15 views

Loop in Related Posts Wordpress

I use this script to display related posts: <!-- Related Posts START--> <?php $query = get_max_related_posts(); if ( $query ) { ?> <div class="td_block_wrap td_block_7 ...
0
votes
1answer
503 views

Query to get child pages of current page and display it in action hook

First I want to apologize if there are spelling mistakes in this question. I'm using Genesis Framework. According to the following answer: https://wordpress.stackexchange.com/a/60295/146574 I'm ...
4
votes
2answers
15k views

How to get the first image gallery of a product in woocommerce in a loop

I want to display a product with a product image and when visitor hovers over that image, it will change to the first image from the product gallery. I am using this code to display the image gallery, ...
0
votes
1answer
13 views

wp_query get the 2nd post

How could I get only the 2nd product in this query? $loop = new WP_Query( [ 'post_type' => 'product', 'posts_per_page' => 1, 'meta_key' => '...
1
vote
1answer
437 views

Pagination - works on local but not live dev!

Can anyone please shed some light as to why the following to print out page numbers works on my local dev server but not on my live server? Both server are running same version of PHP. My Loop <?...
22
votes
4answers
31k views

Why should I put if(have_posts()), is while(have_posts()) not enough?

I have a question about "the loop". <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your ...
1
vote
1answer
45 views

How to change posts order on Category and Tag archives?

WordPress by default order posts in descending order by date. But I want them to be in ascending order by date. How do I turn the order to ascending only for tags and category? I don't want blog post ...
0
votes
1answer
22 views

How to use single.php output in function.php

In single.php, inside the loop the code shows text output. <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', get_post_format() ); ?> $content = ...
0
votes
0answers
12 views

WooCommerce - Loop through sale products by category but restrict to one category per product

I have this loop working at the moment, although products are listed in multiple categories and are looping through multiple times. How do I restrict output to one category per sale product? $count =...
1
vote
1answer
458 views

Alter query using pre_get_posts() if meta_key is present

I am trying to modify the number of posts per page for archive pages that contain category sticky posts (added by the Category Sticky post plugin) to do so I am using the pre_get_postshook and have ...
1
vote
1answer
16 views

How to use offset in WP_Query

Where do I put the offset function? <?php $args = array( 'post_type' => 'post', 'category_name' => 'category', 'orderby' =&...
0
votes
1answer
18 views

How to separate post titles with a comma in the loop?

How do I list all my posts with a comma (but not after the last post)... <?php // WP_Query arguments $args = array( 'post_type' => array( 'post' ), 'tax_query' => array(...
20
votes
1answer
5k views

Some doubts about how the main query and the custom query works in this custom theme?

I am pretty new in WordPress theme development and I'm not so into PHP (I came from Java and C#) and have the following situation in this custom theme As you can see in the homepage I first show a ...
1
vote
1answer
504 views

Loop returning only 1 result

I am not sure as to why when I run my loop only 1 result returns. Here is my code: <?php if ( is_front_page() && twentyfourteen_has_featured_posts() ) { // Include the ...
0
votes
2answers
553 views

Display posts of certain categories to specific user roles

I'm working on a site for a school and the teachers all want to post the homework for their students online, but only so each student can see his or her own class's homework posted by their teacher. ...
0
votes
1answer
3k views

Is it possible to add query parameters on the archive page?

I have a custom post type 'Works', and an archive page 'archive-works.php'. I would like to hide the non-public posts from the archive page, so I added a custom meta box. I also modified the query to ...
1
vote
1answer
32 views

How can marge these loop code?

I just need an idea where to put this code: $term_featured_image_id = get_term_meta( $custom_term->ID, 'wp_travel_trip_type_image_id', true ); $image_url = wp_get_attachment_url( $...
1
vote
1answer
648 views

Ajax Infinite Scroll In Custom WP_Query Loop Not Working

I have set up a custom WP_Query loop for a page template. I am implementing an infinite scroll method via ajax, and the call is successful, but for some reason I cannot get the query to like the paged ...
1
vote
0answers
10 views

Conditional query that displays on Woo product attribute pages

I have a custom query set up that currently modifies the product category pages of my website. I would also want this code to affect the product attribute archive pages of my website, but I am having ...
0
votes
2answers
663 views

Get post id outside loop : Notice: Trying to get property of non-object

I am trying to get the post id outside the loop in functions.php.but what error i am getting : Notice: Trying to get property of non-object in functions.php on line 549 function ...
0
votes
0answers
15 views

Gutenberg Blocks Messes Up Layout?

So we designed a page that includes a section where featured news articles are displayed. The most recent article is displayed on the left side, while the other recent articles are displayed on the ...
3
votes
1answer
450 views

Query Custom Meta Value with Increment

I have a Query searching for a meta value I have added to my posts (meta-select). I have it feeding out in a loop with 4 results. Let's say I want this loop to start with the meta value "2" and work ...
0
votes
1answer
432 views

Post from one loop in different containers?

Is there a way to output posts from a single loop in multiple containers? Ideally I'd like to have the posts title/meta/content etc alternate between first-container and second-container, but I can't ...
0
votes
1answer
449 views

Infinite Loop after Genesis Theme Upgrade

I'm running WordPress on Microsoft Azure, and I've been having a lot of timeout errors any time I try to install or update plugins/themes. (I'm using a custom child theme, based on Genesis.) Today, I ...
0
votes
0answers
18 views

Custom Query with Sticky Posts

I’m trying to write a custom query which filters by category and shows only a certain number of posts. So far that’s a simple thing along these lines: $args = array( 'showposts' => 1, 'cat' =>...
0
votes
0answers
14 views

Display post taxonomy based off custom metabox selection

I am using CMB2 to display a custom taxonomy which is calling the categories from my post and displaying the results within the page backend in a select field. Each page will have the ability to ...
0
votes
3answers
506 views

Carousel Loop only duplicating

I have problem with looping and WP_Query. Any idea how i can implement the multiple carouselitems please check what html output should be in html So basically one of my goal is each div have a pages ...
0
votes
1answer
18 views

How to loop custom posts that have an exact match in taxonomy terms?

I have created a loop to display programs. One of the taxonomies for each program is a grade or grades. Some programs are for 1st and 2nd graders, for example. I would like to display a div in my ...
0
votes
2answers
78 views

Distribute Gallery Images Every nth in Loop

I have added an acf image gallery for archive terms and I would like to take those images and insert one image from the gallery every 3 posts in the term archive. This is what I have so far but I am ...
0
votes
1answer
141 views

Custom post type loop without children

I've created custom post type "Services" with 'hierarchical' => true,. My loop is simple: while (have_posts()) { the_post(); get_template_part('content', get_post_type()); } ...
1
vote
1answer
535 views

pre_get_posts for two loops on same page

I'm using two loops on homepage, one is to show the 3 latest posts, and the other one to show the rest of the posts minus the 3 first posts. I'm using the following code for the pre_get_posts. ...
0
votes
1answer
13 views

ACF - Get ID of relationship field in flexible content

I'm trying to get ID from a relationship field within a flexible content and push it in a array if (have_rows('studio_blocs')) { while(have_rows('studio_blocs')) { the_row(); $...
0
votes
0answers
29 views

New posts not visible

I've a website. It was initially developed by a different developer. It has custom template work done to it. In the wp-admin "projects" can be seen in the menu. When I click all projects, all ...
0
votes
0answers
23 views

Loop through an iteration of 500 results at a time and increment page and restart with next 500

Below, I will explain all the steps and how everything works so you get a better understanding of what I'm trying to achieve. The import_employees function kicks off and grabs the $settings['page'] = ...
0
votes
1answer
55 views

cURL needing to loop through all “next_page”

When using cURL, how would I be able to include a call inside my get_all that basically will loop through all the next_pages, get the data and then outpul it to $response->data when the "next_page" ...
0
votes
1answer
549 views

Category ID returns as '0'?

I'm trying to populate the category id from the category name within the loop. <?php $cat_name = get_theme_mod( 'cat_1' ); ?> <?php $category_id = get_cat_ID($cat_name); ?> &...
0
votes
1answer
551 views

Group posts that matches a term in a loop

I'm working on a website that shows a lot of products, and this is my structure: Product (custom post type) -->Brand (custom taxonomy) ------>Brand A (custom term) ------>Brand B (custom term) -->...
0
votes
1answer
25 views

Add Search and Filter functionality to custom loop

I have a custom post type and a page where I loop through them. I'm trying to implement the plugin Search and Filter to the page, so people can filter the custom posts. However, it does not work at ...
0
votes
0answers
16 views

Loop through and output more than 500 results

I have the following code and below I will explain what all I receive and what the output results too: function import_employees() { $log = []; $name = 'octopus_import_employees'; $...
0
votes
1answer
47 views

Should I reset $wp_query?

I am not totally new on WordPress but the query thing is a bit confusing to me. I searched the web and read a lot of articles, but I couldn't find what I needed. Maybe it could help a lot of people ...
0
votes
0answers
20 views

Multiple post in One Loop in wordpress

I’m converting HTML website to wordpress dynamic and having trouble getting duplicate posts. Code is following kindly please guide me in this regard m new with wordpress and PHP. <div class="...
0
votes
2answers
632 views

divide custom field values in div every two values

i have this html mark-up to sort some data <div class="row"> <div class="col-xs-2"> <img src="images/member-schools/ms1.jpg" class="img-responsive"> </div> <div class="...