Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

The core of the WordPress query, the loop offers an easy way to access post information and display it on your website.

0
votes
0answers
17 views

How to display single post and the 3 previous posts on home and single

I am looking to have my site display a single blog post at a time, with the 3 previous posts displayed by thumbnail/title on the right. I was successful in getting this to work for the current post ...
0
votes
0answers
41 views

How do I use AJAX Query in my posts loop?

I have this function in my functions.php. All the AJAX and Query is working but displays the results of the loop right below the AJAX filter. I want the query loop to display in my main theme's ...
1
vote
1answer
21 views

What's the WP way to load remaining custom posts?

I am displaying custom post types, grouped under their custom taxonomies (basically used @ChipBennett's answer from here: Display all posts in a custom post type, grouped by a custom taxonomy) for a ...
0
votes
1answer
13 views

How can I group by Taxonomy on Custom Post Type while filtering out based on custom Meta

I hope I can explain this without being too confusing. I have a site where I have a custom post type that has two custom hierarchical taxonomies ( categories ) and each post also has a meta filed ...
0
votes
2answers
23 views

why get_post_meta is returning 0?

I'm trying to show all the posts on a page with an audio player in it and for that I'm looping through posts in the following manner: <?php $posts = get_posts(); $ID; foreach( $posts as $item) { ...
0
votes
1answer
16 views

show loop id post , only first id can read

I have a script , show post by id , and id post from array here my code : if ( have_posts() ) : while ( have_posts() ) : the_post(); $f = cherry_get_option('blog-featured-post',false); foreach ($f ...
0
votes
1answer
58 views

How to get post ID in a Page?

I'm trying to list all of my posts in a page(with post's content). Everything is showing correctly but the audio player which uses post id to get the URL of an attachment in the post is not showing. I'...
0
votes
0answers
10 views

How to include files in the loop via ajax

I create plugin and I need to include multiple files via ajax. When I don't use loop this code work: include_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'sections/a.php' ); When I try to ...
-1
votes
1answer
16 views

foreach return displays double results

Seems I have a little bug in my WP code. When I add the shortcode to my page, it displays the results twice. If I use echo this will post at the top of the page, I want to enable to shortcode so it ...
0
votes
0answers
12 views

get archive link for custom post type for a custom taxonomy term

I have a couple of custom post type with a common taxonomy. I'm able to list custom taxonomy term page but having a problem with getting the archive link to the custom post type for that taxonomy term....
0
votes
0answers
12 views

Retrieve a specific ACF Repeater Sub field similar to a veriable

I have a veriable $journey_value = $_GET['onward-date'] != '' ? $_GET['onward-date'] : ''; And in a custom query I want to retrieve a specific acf repeater suv field simillar to the above veriable. ...
0
votes
1answer
13 views

how to get category`s slug in WP_Query loop?

i use below code : //custom post = project //taxonomy = project-category $args = array( 'post_type' => 'project', ); $query = new WP_Query( $args ); // The Loop if ( $query->have_posts() )...
0
votes
0answers
21 views

subtracting the current post form then whole loop, which is generating all CPT titles

<select class="title_select minimal"> <?php $loop = new WP_Query( array( 'post_type' => 'plugin', 'posts_per_page' => -1 ) ); ?> <?php ...
-2
votes
0answers
23 views

show all posts of a given post-type without changing the PHP anywhere in any way

show all posts of a given post-type without changing the PHP anywhere in any way. Everything should be done only from the WordPress GUI. Is this possible via WordPress core (without any plugins)? ...
-1
votes
1answer
20 views

How to write a query-function as a query-shortcode?

I ask this question as a follow-up to this one. I have this query-function in functions.php but AAMOF I don't want to change functions.php at all (besides for CPTs). I'd like to print the same data ...
-2
votes
1answer
21 views

Creating mixture of shortcodes to use in the visual/text editor

I am attempting to make a page on my site that has a mixture of different kinds of content. So I'd like for the first part to just be the_content, but then beneath it calls to posts under specific ...
0
votes
3answers
39 views

Get all posts as an array ID => Name

I need to query all of my posts as an array in example: 'options' => [ 'Post ID' => __('Post Name'), 'Post ID' => __('Post Name'), ], How can i do it? tried this but it gives me ...
1
vote
1answer
19 views

How to show posts with multiple tags on tag.php?

On my tag.php page, I want to show posts with multiple tags... I have something like this: mypage.com/tag/tag1+tag2+tag3/ $tags = get_queried_object()->slug; //returns only 'tag1' !! $args =...
-1
votes
0answers
14 views

WordPress Loop Visually Presented

My last development work on a CMS was on Zikula a decade ago. I would like to start venturing into WordPress development. I was informed that the WordPress loop is the key. Is there a good visual ...
0
votes
1answer
16 views

Injecting content with $wp_query->current_post restarts from zero on paged pages. How to inject content after X posts, regardless of pagination?

I am creating a shortcode that outputs a custom loop. Within the loop while, I am injecting certain content after a particular post count. This is done by checking the current_post number. This ...
0
votes
0answers
34 views

Custom sort by menu_order not working when set as Default product sorting

I have products with Gallons as size so I want to list products in ascending order by Gallon size so I added numeric gallon values to the menu_order attribute field. After adding the below code to the ...
1
vote
0answers
52 views

Apply an Incremental Counter in an Array Function

I'm attempting to incorporate an incremental counter inside an array function, that is, in turn, inside the post's while loop. However, I am only able to get it to count to 1. This is what I ...
0
votes
2answers
20 views

Loop posts based on permalink term

I have setup my custom post's custom taxonomy's permalink structure to be: custom post type > custom taxonomy > post (from this helpful Q&A) Now I'm hoping to be able to code taxonomy.php to ...
0
votes
1answer
23 views

Advertisement in Loop Posts wordpress

I'm new here I want some help from you in terms of coding in wordpress. The point is that I want to make advertising between items as shown below: <div class="row top-articles"> ...
0
votes
1answer
12 views

ACF - Get unique values of array

I need to get unique values of array to use in a filter. This is my code <?php $newsArgs = array( 'post_type' => 'sistemas-sanitarios', '...
0
votes
1answer
31 views

Get a specific size from wp_get_attachment_image_src

I have this section in my website where i use wp_get_attachment_image_src() to get all the images associated with the post, but now you want to get a certain size (size: listing_grid): <?php $...
0
votes
2answers
25 views

Separate First Post Loop

I'm trying to use the <?php rewind_posts(); ?> feature to use two loops on my homepage template. Does anyone know how to stop the first loop after the latest post? Here is my Code: <?php ...
0
votes
2answers
23 views

How do if all posts has this category ID then do this

I need a wordpress function that search all the posts inside my website and if one or multiple posts have the category ID (example 25) echo "yes", else echo "no" I was trying to do: if ( ...
0
votes
1answer
90 views

How to get post ID from button and pass title to Modal

<div><?php echo wp_get_attachment_image($image_upload,$size = 'full');?><br/> <span class="name"><?php echo $title ?></span><span class="jobtitle"><?...
0
votes
1answer
16 views

the loop printing post in one grid

I am trying to print my wordpress post into 2/2 grid but I think my div's are messed up. <div class="grid-container"> <?php if($query->have_posts()): ...
1
vote
2answers
61 views

Split WordPress Latest Posts in Multiple Columns and Rows with one single loop [closed]

I have this layout I am trying to implement - https://drive.google.com/file/d/1cP831xAM1F5CT3HEmedCBkINwiCC18Rb/view And I have created a news template, but I need to get the posts to display like my ...
1
vote
0answers
47 views

Calling & display certain product category loop and pagination on the homepage

Need some help with wordpress and woocommerce functions. OK, the situation is, I have a homepage that use archive-product.php template. It shows latest 28 products per page. This is the product loop ...
1
vote
0answers
41 views

How can I add extra word in permalink when someone click download button?

I am new in here. I actually do not understand really it a WordPress related question or not. I think it is. My site runs into WordPress. My question is when someone clicks my post it shows a download ...
2
votes
2answers
327 views

How does WordPress ensure plugins run at the same time and how does it solve a plugin's dependency on another one?

Say I have a plugin which fires the plugin_1_action when it initializes. Now, because I wanna extend that plugin, I'll hook into plugin_1_action, but what if my plugin was installed after that plugin?...
1
vote
2answers
36 views

Template structure

Question regarding template structure: In a custom loop, I inserted a get_template_part('resources', 'layout') which contains the following markup: <div class="custom-content"> <?php ...
0
votes
1answer
31 views

Repeat array inside array through while loop

I want to repeat this array: array( 'taxonomy' => $tax, 'field' => 'slug', 'terms' => $cat, ) because I am getting the value of taxonomy and categories from custom sub ...
0
votes
2answers
37 views

Custon Content within WordPress Loop

I have created a WP loop to display Services from 'Services' Custom Post Type: Here is the code: <?php $services_loop = new WP_Query( array( 'post_type' => 'service', 'posts_per_page' =&...
-1
votes
1answer
29 views

pull 500 post of many from database [duplicate]

I'm using the premium theme, which is using <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> this code to pull post from database but it pulled all the ...
0
votes
1answer
29 views

Trying to Create a PHP Variable for post_type that can be referenced Site Wide

I have several sites with several custom PHP widget loops I've created. I would like to reuse these widgets in other areas and site, but with different custom post types. The only unique thing in ...
1
vote
1answer
37 views

Loop through custom fields with similar label / common chars in label

I created several custom fields for my custom post type "books" There is a checkbox for languages. Whenever a language gets checked, several custom fields for that language get added (i.e. title, ...
2
votes
1answer
31 views

wordpress query in header won't reset and corrupts other loops

In a template part in my header, I have the following code: $args = array('post_type'=>'weather_today','orderby'=>'ID','order'=>'ASC','posts_per_page'=>1); $query = new WP_Query($args); $...
2
votes
0answers
17 views

Fix inefficient loop breaks post.php on form submit

As is, this loop works fine. Although I feel like its inefficient because it doesnt need to keep updating the nonce counter each time it loops, that only needs to be done once. So when I try and move ...
1
vote
2answers
126 views

Add the “active” class only to the first loop item in a WordPress query [closed]

I have a query as shown below: <?php $query = new WP_Query( $wpplnum ); while( $query->have_posts() ): $query->the_post(); ?> <div class="carousel-item col-md-4 active"> ...
0
votes
0answers
13 views

wp_get_archives() --> only show posts, a user is allowed to read?

i'm trying to build a navigation in which all posts are listed in a sidebar (all the time) -> but only the ones a user is allowed to see. i tried to do this with wp_get_archives() which gives me a ...
0
votes
2answers
34 views

How can I add multiple 'tax_query' arrays via a loop?

I'm trying to build functionality (using the Advanced Custom Fields plugin) to list information in a page template for all custom post types ('Product') that have specified taxonomies. This is my ...
1
vote
2answers
89 views

WP_Query to loop a Custom Field, Custom Post Types do not show

I am using WP_Query to loop a Custom Field, Custom Post Type that shows 6 Menu Icons across 6 horizontal fields. The icons do not show on the page. My query code is: <?php $loop = new WP_Query( ...
1
vote
3answers
48 views

How can i display post loop in table format?

I am creating a comparison table and the issue is in while loop i am not able to put the "tr" in proper place. I need layout like this <table> <tr> <td>post title 1</td> <...
1
vote
1answer
19 views

How i can add 'N' page of 'N' pages under posts loop?

I want show number of current page and count of all pages, near my posts paginations. I am talking about this
0
votes
1answer
59 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 ...
0
votes
0answers
26 views

Wordpress For Loop Prints Unwanted Extra Paragraph Element

I have the following code to list my authors in my sidebar except for the admin account. It works very well in function. However, it prints an extra paragraph element that includes two ancor tags with ...