Stack Exchange Network

Stack Exchange network consists of 175 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

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.

0
votes
2answers
16 views

adding or removing endforeach; throws error!

This is my code, where i keep getting either error: unexpected endforeach; if endforeach is used or unexpected end of file if i don't use endforeach; It's driving me crazy!! <ul id="portfolio-...
0
votes
1answer
27 views

post_type incorrect for custom post type

I am trying to display a different template depending on the post type. I have registered two custom post types called resource and contact. When I try to get the post type in search.php (using ...
0
votes
0answers
26 views

Loop (for search results) returning right posts, but wrong post type

Hoping this isn't already asked/answered, but it's a tough one to search. I've got a site based on the Flatsome theme which uses custom post types (through various plugins). The search page works in ...
0
votes
0answers
16 views

Sort custom post type by other custom post type field. (Places by their reviews mean vote)

I'm trying to sort Places (first custom post) by its Reviews (second custom post) average (mean) vote. So, basically I have two custom post types, one is Places and the other one is Reviews. Reviews ...
0
votes
1answer
34 views

How to add sort order to incremented and paginated category loop

I used this in a loop on a category template to get a numbered lists of posts that continues in the next page: <?php $mypage = (get_query_var('paged')) ? get_query_var('paged') : 1; $ppp = ...
0
votes
2answers
22 views

Skip latest 3 posts from loop

I downloaded a starter theme (Underscores). I want to exclude first 3 post from my loop on index page. Here is the loop; <?php if ( have_posts() ) : if ( is_home() && ! is_front_page()...
0
votes
1answer
25 views

Get post meta value outside of the loop

I'm working on an extra function to list different stuff, My function looks like: "display all hotels for a specific city" -> hotels is as CPT and CITY as custom Tax. So for exemple, lets display ...
1
vote
1answer
37 views

This AJAX Code Doesn't Work - Looking for elegant solution

I am trying to utilize AJAX on my WordPress site for posts as a user scrolls. I followed this tutorial but it has no effect on my WordPress website. I have used a plugin that works, but I'd much ...
0
votes
0answers
12 views

Wordpress - Get 2nd level child categories while looping 1st level child categories

I'm trying to loop and get the 1st and 2nd depth child categories of the 'Parent Cat 3' which has the id of '17'. Here's a simplified form of my category structure PARENT CAT 1 PARENT CAT 2 PARENT ...
-1
votes
0answers
15 views

I want to run a custom loop where i want to fetch those post first which will expire soon using meta field (last_date) [closed]

I have used meta field for last date and i want to run a custom loop where i want to fetch those post first which will expire soon
0
votes
1answer
27 views

Query post with content only

I need to loop through the last 3 posts movie, but only those which have a content not empty. I used to do as follow when I used the ACF editor instead of the native one. movie-content refers to ...
0
votes
1answer
56 views

get_next_post() and get_previous_post() return wrong posts

I’ve been trying to retrieve the next and previous post in one of my Wordpress templates. Please note that I want to get the full post object instead of just the pre-formatted links to the posts. The ...
0
votes
1answer
29 views

Moved a website and excerpts don't work for old posts

I moved a WordPress website to a different host and all post excerpts stopped working in the blog list. When I make a new post they appear fine but doesn't show for the old posts. I peaked into the ...
0
votes
0answers
33 views

Pagination for a cpt filtered with a category

I was tasked with creating a posts aggregator that fits seamlessly into the category nav-bar. For this to work, I could not use the category-list.php that exists, for it is full of workarounds and ...
0
votes
1answer
11 views

Prevent function from triggering on current page

I created a list of posts, each post about a car model. After that, I created a post about the best car models. This post grabs each post about every car model and displays them in a snippet list ...
0
votes
0answers
24 views

Problem with my loops

I am French. Sorry if i make mistakes. I have two problems. The first, I have a page that shows all paying activities sort by date. The 'posts_per_page' does not work When I put 10, it shows 8 ...
0
votes
1answer
16 views

Bootstrap tabs are not being clicked in WordPress loop

I am trying to show some Bootstrap tab contents within a WordPress loop. The tabs are not being clicked. Here are the bootstrap codes: <ul class="citenav nav nav-tabs" id="myTab" role="...
0
votes
1answer
25 views

get_post_type is always post

Sorry to bother you all with this, but it's driving me nuts and I know I've missed something obvious. I want to display different post types, differently, within the loop. I'm trying to get the post ...
0
votes
1answer
29 views

Custom WP_Query id

I need to create a WP_Query that lists only a specific post of a post type, I already have this in the query, but my problem is that the query filter receives via get the ID, With that suppose I have ...
0
votes
2answers
30 views

Best choice for multiple loop in page?

My home page include five loop. currently i use wp_query but is it optimized ? best choice with get_posts ? my code looks like that // First loop $args_dogs = array( 'post_type' => ...
0
votes
2answers
25 views

Where paramaters of a custom function are coming from inside the loop?

I have this piece of code and, although it works, I do not understand how. First, I created a custom post type into my mu-plugins folder: function actor_init() { $args = array( 'label' => '...
0
votes
0answers
22 views

get_category_link() returns wrong url, result is `http://my_site_url.com/http://my_site_url.com/my-slug` instead of `http://my_site_url.com/category`

I am using the following code to access my categories: <?php $categories = get_categories(); foreach($categories as $category) { echo '<li><a href="' . get_category_link($...
0
votes
1answer
14 views

Return to the beginning of the results of a for loop

I am currently doing a little script (and I am rather beginner), I would like to know how to return to the result number one of a for loop after the table containing the results have been traveled? ...
1
vote
1answer
22 views

A to Z List of Custom Post Type in three columns

I want to display custom post types A to Z Index in three columns, but it just lists the first post under each alphabet in three columns, I think there is some issue with the loop but can not figure ...
0
votes
1answer
23 views

How to list articles by year based on url?

Hie all, I am trying to list posts by year based on the provided url (for example: wordpressite.com/2004 - this should list all articles created in 2004), unfortunately all suggested methods from ...
0
votes
1answer
19 views

Loop stopped working

I have a huge issue and I broke my had trying to find the correct solution. I have a following loop code. This loop is inside my page-product.php file: <?php $terms = get_the_terms( ...
0
votes
1answer
29 views

Custom taxonomy.php not working

I have created a custom taxonomy called "series" (code below) and two pages: taxonomy.php and a taxonomy-series.php 1)I noticed that siteurl.com/series does not work I get my 404 page, but if I were ...
1
vote
2answers
41 views

Display post list with different styles

I'm about to convert my Bootstrap template to a custom Wordpress theme and have a little issue. I want to display all of my blog posts. So far, it is working well. But here is the thing: Because of ...
0
votes
0answers
26 views

Custom menu attributes (wp nav menu)

I've created my own set of menu attributes function menu_post_meta_fields( $menu_item ) { $menu_item->icon = get_post_meta( $menu_item->ID, '_menu_item_icon', true); $menu_item-&...
1
vote
2answers
54 views

Create A Loop With A Variable Number of Posts For Each Bootstrap Row?

I'm attempting to create a single WP loop, using a custom query, to display a custom-post-type - using Bootstrap 4 markup. The complicating part for me is, I'd like the number of posts for each row ...
1
vote
1answer
12 views

Duplicated posts on category page

So, I have archive.php file with this part of code <div class="column is-full is-three-quarters p-small"> <?php while ( have_posts() ) : the_post(); get_template_part(...
2
votes
1answer
30 views

Group posts by custom field

I am trying to display a list of all child pages using wp_query and so far I have created a function that retrieves all the child pages for the current page, however I need to sort these pages into 2 ...
0
votes
1answer
24 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
13 views

Display posts side by side with custom query

I'm trying to organize my posts side by side but they keep being displayed vertically. This is my code: <div class="row agenda-box justify-content-start padding minheight-40"> <div ...
0
votes
1answer
37 views

How to get current post category details inside “loop”?

I have a rather simple problem I can't solve. I have custom styling for my cards and one of the elements of the cards is the category, when I access the_category() from the Loop it comes with its own ...
0
votes
1answer
34 views

Custom Query Pagination not working on static front page

I'm trying to add pagination to my site but it isn't working. Here's the code: <div id="gridcontainer" class="carousel"> <?php $currentPage = get_query_var('page'); $counter = ...
0
votes
2answers
27 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
16 views

How to count posts posts if they are in a separate content page?

I am using a content page to render elements from my "Loop", I would like to count the post to get my current position as this would determine the size of the card I display. My (html, css cards you ...
3
votes
1answer
18 views

Get array of posts from the current archive page loop

Classic WordPress loop (for example in archive.php) looks like this: if ( have_posts() ) : while ( have_posts() ) : the_post(); get_template_part( 'template-parts/content', ...
0
votes
2answers
20 views

Get gallery in loop through ajax

So, calling this PHP from click through ajax I manage to display Title and content in my modal. But when the code gets to get_post_gallery it always returns null. $the_query = new WP_Query(array('p' ...
0
votes
0answers
32 views

Implement AJAX load more button in custom post loop

I need help implement a load more button in some custom loops in my custom wordpress theme. I'm experiencing some problems in the final step, I'm not able to print the function. This site is a ...
1
vote
1answer
47 views

wp_query to find posts by year and month

I need to create sorting by year and month of custom post type in taxonomy archive page. Like this: Here is shown year, if post exists in that year. And Highlighted month if post exists in that ...
0
votes
1answer
25 views

Archive: Lists itself

So I have created an archive.php, set everything up, and my archive page works fine. Now I was wondering, of how I should prevent the archive page from listing itself. When accessing the page called ...
1
vote
1answer
17 views

WordPress loop: exclude if it is the latest post

I do not want to show the latest post on a particular page. I am using a loop per category as I require these loops on various pages. So the thing is, I am running 3 separate loops for each category, ...
1
vote
1answer
25 views

Posts will not display on page-mypage.php

Something is really tripping me up. I have been used to querying posts via custom queries however based on research lately I have learned that for the most part this is a big no no. So, in testing the ...
2
votes
0answers
30 views

Multiple WP_Query loops with Pagination Not Working

Please can anyone help me out here? I'm really stucked with this code. I want to create a multi post loop on my home page with each loop having its own pagination. The first loop is for recent post, ...
2
votes
1answer
27 views

the_content() in single-{post-type}.php problem

I have Custom Post Type "pjesma" (song), and the only way I managed to display the content is like archive-pjesma.php. It works fine: <?php get_header(); global $post; $args = array( 'post_type' =...
0
votes
1answer
32 views

posts_per_page is not working by term

I'm trying to limit the posts, but it does not work. It shows them all. Why posts_per_page does not work here? <?php // Output all Taxonomies names with their respective items $terms = get_terms( ...
0
votes
1answer
36 views

Multiple Custom Post Type queries, how to DRY it up

I need to be able to display the latest post from 4 different custom post types and then use those posts inside a carousel. Everything is working fine but I'm not happy with how my code looks as I'm ...
0
votes
0answers
30 views

Staggering featured post using 'sticky'

So I have Custom post type that occasionally will have posts marked as 'featured' Client would like to use the 'sticky' feature of WordPress to pick which posts from the CPT are classed as featured ...