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
0answers
16 views

Why do my custom post type show up in all pages?

I was doing a page with template-parts to call my custom post type but the posts are popping up across the top of the site, I think it's because of the query , when I deleted it they stop popping up ...
0
votes
1answer
16 views

Yoast taking over my Wordpress title tag

I have this code: <h1><?php the_title(); ?></h1> That is meant to display the title of my blog post only. But because Yoast has a SEO title of something else, it is displaying ...
0
votes
1answer
9 views

Latest posts feed with a specific post always first

I have a latest posts slider working nicely. I would like to push a specific post (ID 123) to always appear first. I believe I could run multiple queries but every attempt has failed. I'm running out ...
0
votes
2answers
33 views

loop in single.php of the same category

How can I put a loop in my single.php that shows the posts of the current category of the single and following the code structure that I have? The question comes, because I can not find the correct ...
0
votes
3answers
16 views

Get custom taxonomy value of post and output posts in same taxonomy

I'm trying to show related videos on my single post template. I've set up a custom taxonomy called 'sub-category' in Posts. I want to get the sub-category of the current post and loop through any ...
0
votes
1answer
19 views

How to create an IF statement in the Main Loop for Custom Post Types

Firstly, this is my first WP project and I'm learning as I go... I know this is probably an easy thing to achieve, but for some reason I'm having trouble getting it to work... so apologies if this is ...
0
votes
1answer
15 views

Loop through ACF taxonomies and output associated posts

I have a page template that loops through all existing post categories and outputs 5 associated posts for each category. I want to change this so it only outputs the categories I have selected in an ...
0
votes
0answers
7 views

How to use a foreach loop to create a dynamic post by fatching pods page

I have got the result in PHP but facing issue in WordPress with pods to create the following dynamic post <?php // an array to fetch pods page $num =array("10"=>54, "9"...
0
votes
1answer
19 views

Pagination Error : Duplicate argument being outputted

I've been writing a custom search.php loop for some time now and I'm running into a weird problem. My php argument is outputting some unexpected results by repeating the template file. Currently I ...
0
votes
0answers
15 views

Store CPT 'Reviews' average ratings to a WordPress DB table or to a DB custom table?

I am working on this portal in which users can review the services (with description and rating) of a cultural place. BASICALLY, I created two Custom Post Types (CPT) with Pods, one is ...
0
votes
0answers
14 views

How to show text near a specific word/tag/category?

can someone give some examples of code that I can use in the tag and category loop pages, which will give out the content near a word? Here is an explanation. The default function of the category and ...
0
votes
1answer
27 views

Exclude a Woocommerce product from WP_Query

I'm using a WP_Query for get products from categories, $default = array( 'post_type' => 'product', 'orderby' => 'date', 'order' => 'DESC', 'post_status' => 'publish'...
0
votes
0answers
38 views

Loop is breaking my theme. How can I fix?

When my theme tries to load home.php, archive.php or any page that uses the loop, the page will stop loading exactly at the point the loop should begin, even the wpadmin bar won't load. If I navigate ...
0
votes
2answers
18 views

Previous and Next links not populating, have I missed something?

I'm working on a very simple theme. I have tried adding next and previous links and cannot get them to work. After trying a few different things, I ended up with this index.php (mostly based on ...
0
votes
1answer
28 views

Combine multiple separate lists into one

I have a custom query for my taxonomy of: $terms = get_terms( array( 'taxonomy' => "issueCompanion", 'hide_empty' => false, 'fields'=>'all' ...
0
votes
2answers
37 views

Add all category as classes in foreach loop

I am trying to modify a portfolio plugin with filter function. The current code for listing to post items is: <?php class FullwidthPortfolioGallery extends ET_Builder_Module { public $slug ...
0
votes
0answers
21 views

Custom meta fields not showing up in WP_Response Object via custom endpoint

I created my own Custom Post Type called person and a corresponding end route. I can modify my posts with the endpoint, using functions as wp_update_post,wp_insert_post and get_posts. I am facing a ...
0
votes
1answer
12 views

Pull in taxonomy field of custom post type in new query

I have a Custom Post Type named companion. Via Companion I create articles which are then associated with my custom taxonomy issueCompanion. Imagine issueCompanion as a publication which is released ...
0
votes
1answer
36 views

How to use alternate post layout at key points in post loop?

How can I intervene in my post loop output to show 3 posts in alternate mark-up, and then resume? I have a post loop that calls my post card template fragment, card-pair_top.php, to display like this....
0
votes
1answer
43 views

WP ForLoop to compare meta information of posts to determine what post to display

The short of what I am trying to do here is: I want to display only one post based on a date stored in a custom field. I only want to display the post if it meets two conditions 1: The date needs to ...
0
votes
0answers
17 views

Error in the page of a CPT file in WordPress

I have a CPT of podcast type implemented in my WordPress. I had to do a type 301 redirection since the plugin that manages the podcasts (Seriously Simple Podcasting) did not let me modify the ...
-2
votes
0answers
15 views

How to Display only value and exclude index from loop jquery?

In jquery how to remove index from value. I have doing following code var $values = $.map(domelts, function(elt, i) { return $(elt).val();}); var option = ''; for (var i=0;i<$values.length;i++){ ...
0
votes
1answer
19 views

WordPress loop by meta key that is an array? and how loop multiple arrays

How can I get loop of posts by meta values that save in a meta_key that is an array like that $sharedHosting_plans_fields = Array ( ...
0
votes
3answers
35 views

'posts_per_page' => '10' does not show any post

everybody, I have created a custom_post_type; function create_post_type_veranstaltungen() { register_post_type('veranstaltungen', array( 'label' => __('Veranstaltungen'), 'public' ...
0
votes
3answers
22 views

Category tags with comma's

I have in my code the following variable to call the title of the categories. <?php $categories = get_the_terms($custom_args->ID, 'veranstaltungen-category'); foreach ($categories ...
0
votes
1answer
16 views

ACF meta_key and meta_value break loop

I have a CPT with post type of 'recipe'. I have several ACF Advanced Custom Fields in the CPT. My loop WORKS correctly when it is written like this: <?php // args $args = array( 'numberposts'...
0
votes
0answers
11 views

Show the subcategory name based on current product

Hi I can display subcategory name in current product page (single product page) but it showed all the subcategory name. I just want to show subcategory name based on the product selected. I have one ...
0
votes
0answers
21 views

Custom query for custom post type not getting correct post ID

I have written a custom query here: <?php $the_query = new WP_Query( array('post_type' => 'video', 'posts_per_page' => 10, 'post_status' => 'publish') ); ?> <?php if ( $the_query-&...
0
votes
0answers
20 views

Recent Posts Loop repeats the excerpt on every post

So, I have this string to show recent posts on my page, but it the excerpt of each post is always equal the first post. what is wrong? see Blog section of my website query_posts( $args ); if ( ...
0
votes
0answers
28 views

How to create a A-Z glossary

I am working on a plugin that lists all the available sites on our multisite, I have it working but was trying to find a way to navigate by letters or just create an A-Z glossary. <?php function ...
0
votes
1answer
43 views

How to output and alert message when updating a post

i want to prevent a duplicate entry for a CPT, so i'm querying the db to find if the record already exists and return if get_result() is true $query = 'SELECT * FROM `wp_postmeta`WHERE `...
0
votes
1answer
9 views

How to get all multi-select user meta values and add them to an array?

I am trying to grab meta_values from a user profile's multi-select field, and convert them to usernames, which I will then input into an array. Let's say that the user has selected two options (out of ...
0
votes
1answer
13 views

How to get user ID's from multiple usernames?

I am trying to produce user ID's from multiple specific usernames. The usernames are pulled from a profile field, and any number of usernames will be called. I want the user ID's from each of the ...
0
votes
0answers
17 views

Duplicate posts on archive page

I am loading posts through ajax and it seems new load produces duplicate posts on archive standard loop. This my code I have tried several methods with $do_not_duplicate but it seems none worked or I ...
0
votes
1answer
22 views

Don't print customizer styles when no setting has been used

I'm adding some options to a theme through my plugin, I want to change this theme styles and I'm almost there... Now I need to know how I can hide the <style> tag when no settings are changed (...
0
votes
1answer
11 views

get_posts changes main query

Here is my code in single.php : <?php if (have_posts()):the_post() ?> <h3><?php the_title() ?></h3> <!-- Prints `Hello World` --> <?php if (!empty($...
0
votes
1answer
24 views

Pagination broken after using 2 loops to show content

I wanted to use different HTML for the first post in a blog. I did it by making 2 loops. Unfortunately this has stopped the pagination from working. I guess it is because I am creating a new query to ...
-1
votes
1answer
20 views

For each loop will not append to the_content hook

I'm using the filter to append items to the content on one page only. It's fully working except for the ordering of the $whole variable. The title is appearing after the content but the for each loop ...
0
votes
2answers
24 views

Exclude posts from loop by term

Here is how the loop looks? I need to exclude a few posts with the custom term, how can I manage it <?php global $post, $PIXAD_Autos; $Settings = new PIXAD_Settings(); $settings = $...
0
votes
0answers
15 views

Display all posts from specific category and CPT

Currently, we are getting all posts from a specific category using the following: $args = array( 'post_type' => array('post'), 'cat' => 1247, 'posts_per_page' => 4 ); What we'd ...
0
votes
0answers
12 views

How do I keep the table row width after adding PHP for ID and Class name?

I am writing a custom post type for a schedule posting page. <section class="schedule"> <?php $crgs = array( 'post_type' => 'schedule', ...
0
votes
1answer
22 views

Only show first image in foreach loop

My loop shows a list of values, and underneath them, the post title and image for the value. The problem is that because some values are associated with multiple posts, multiple images show up. I ...
0
votes
1answer
15 views

Looping to organize and display custom posts by category using PHP and WordPress

I am developing a page that requires me to display a list of categories for a custom post type in an accordion-style dropdown. The category name will act as the accordion title, and the contents are ...
0
votes
1answer
42 views

Custom query pagination with php parameter as arg problem

I have create a loop with a custom query. This query contains a php parameters that i m getting from url with GET method. The problem is that the pagination (even if it counts the posts correct at ...
0
votes
1answer
28 views

Array ids post to function have_post

I get as result of a main sql an array of post IDs, now what I need that Array of ids post to obtain the information and be presented in the following way: <?php $ids = [1,2,3,4,5]; // ...
0
votes
0answers
27 views

Woocommerce featured products query no longer working

I have a query that's stopped working since Woo 3.6 upgrade I think. I'm trying to get products in a category that are featured. Any help would be much appreciated:) <?php ...
0
votes
0answers
50 views

Trying to get property 'post_content' of non-object

I'm creating a wordpress theme and I created a shortcode to show an abstract of a post (the first image, title, and link) from a post (by its ID). To do this, I created a function to get the first ...
0
votes
0answers
14 views

Show post first in loop based upon meta key, in array of multiple categories

I am trying to achieve the following. Using the wordpress theme newspaper, a custom block is displaying the four most recent posts from a couple of categories, which are set in a tagdiv composer that ...
0
votes
2answers
24 views

Include future posts in tags and in search

I am using something like this to query and display future or scheduled posts on my homepage: <?php query_posts('post_status=future&posts_per_page=10&order=ASC'); while ( have_posts() ) : ...
1
vote
1answer
19 views

Including post thumbnail url in loop's post object to reduce number of queries

I'm working now on high performance Wordpress website and it requires me to analyze a lot of queries, caching options etc. I've discovered that if you use get_the_post_thumbnail() even within the loop,...