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
7 views

slider create a problem by using custom post type

I'm trying to create a slider using custom post. but, I was failed repletely. So, Help me build an awesome slider or anyone can give source code in the slider.
0
votes
2answers
1k views

How do I show the post title if an advanced custom field hasn't been used?

I've got an archive page for to display custom post types. Within the WP_Query that displays the custom posts types I want to display an ACF (Advanced Custom Field) or, if the user hasn't filled out ...
2
votes
4answers
4k views

Why am I getting an infinite loop with have_posts?

I have the following code, which causes an infinite loop for some reason. Can anybody explain what's going on please? Thanks! <?php $flagged_stores = new WP_Query( array ( 'post_type' => '...
-1
votes
0answers
22 views

WP_Query - Bug with multiple post types

I'm creating a WP_Query, and I need it to get multiple post types, and it's working REALLY strangely. I have 3 post types: 'equipo','accion' & 'publicacion'. And my code looks sth like this: $args ...
0
votes
1answer
703 views

Problems with WP_Query, Loop, a condition and Posts per Page

I am creating a website and I have Custom Types (Plugin: Types). These Custom Types are called 'Veranstaltungen' --> they are Events. All of these Events have a starting date ( start-datum ) and an ...
0
votes
0answers
15 views

How to make toggle content from custom posts

I'm looking a way to toggle some content from custom post type. ex : https://vignerons-cairanne.com/fr/vignerons-cairanne/ I wan't something similar, when you click an image, it display the content ...
1
vote
5answers
4k views

How to order posts by title after they have already been sorted by category

I'm not an expert at much, so please excuse me if this is an easy question... but it's got my head spinning. I have an archive template (adapted from a standard 'enfold' theme template) which I am ...
0
votes
0answers
9 views

index page shows loop of all posts, I want to change it into loop of 'exhibitions' category

Index page shows loop of all posts, I want to change it into loop of 'exhibitions' category my website is on my localhost but I am using this wp theme http://expositio.wpshower.com i don't know php ...
0
votes
1answer
582 views

Next / previous posts link doesn't show up with Posts 2 Posts

I am working on a Wordpress project where I use the Posts 2 Posts plugin to show posts from one post type to posts from another post type. This works great but for some reason my next_posts_link() ...
0
votes
2answers
867 views

how to use custom loop in the_content filter

Trying to use the the below code for my CPT 'state' like add_filter('the_content', 'my_custom_loop'); but the trial and error is not getting me anywhere. I can't use a single-{post_type}.php since i ...
1
vote
1answer
26 views

Exclude category from

I am trying to exclude a category from <?php the_category(', ') ?> inside my loop. I came across the following code on CSS tricks that says would solve the problem. You add this to the functions:...
0
votes
1answer
7 views

wp_get_attachment_url not fetching URL?

the below code does not seem to return an image url at all, chrome inspector says source is unknown foreach ($subcategories as $subcategory) { $link = get_term_link( $subcategory->...
1
vote
1answer
742 views

Posts loop with pagination on a single post page

Today, I need your help. On my pages I have a sidebar with : <div class="sidebarActu"> <ul> <?php $i = 1; while ( have_posts() )...
6
votes
2answers
29k views

Get first post from wp_query

How can I get the first post from a WP_Query result? $connected = new WP_Query( array( // Arguments )); // This doesn't work.. echo $connected[0]->post_name;
0
votes
0answers
22 views

Check if current post in loop is last on current page

I am developing a WordPress theme and want to determine if I am at the last post of the current loop page. <?php get_header(); ?> <main id="main"> <!-- ======= Blog ...
0
votes
2answers
816 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="...
0
votes
1answer
861 views

Custom Post Type + Category archive

I have created a WP stack with 3 post types: 1. Post (default) 2. Event 3. Place These 3 post types share the same taxonomy, that being the default WP category, here are some example categories: ...
0
votes
1answer
906 views

How to check if there are posts with the same tag

I have this code but I can't get to delete the div with the class otrasObras <?php $test = ""; $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { $test .= ',' . $...
0
votes
1answer
1k views

add offset to archive page

Hi how can i add offset into archive page loop? <?php if (have_posts()) : while(have_posts()) : the_post();?> <a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a&...
0
votes
1answer
1k views

Style first 3 posts differently and use a 2nd loop to get rest of posts / offset and pagination broken

I'm working on a theme and I am having trouble with loops/pagination breaks when using an offest. I looked online and tried to use only 1 loop (per this post) but I'm having trouble making it work. I ...
0
votes
0answers
12 views

How to display site title, if logo is missing in customize?

I want to display website title, if logo is missing in customize my codes for logo, functions.php add_theme_support( 'custom-logo', array( 'height' => 100, 'width' => 400, ...
0
votes
1answer
19 views

Duplicated <a> tag in loop

I stuck on this issues, looks simple but can't find resolution to fix it. I have such loop: <div class="features-items__wrapper"> <h2><?php echo $currentTitle; ...
-1
votes
1answer
2k views

How do I create a template page to show 3 blog posts?

I have a blog theme that I created which shows one post per page. To do this I simply set up single.php the way I wanted, and I have some code that links the 'blog' item in the nav to the latest blog ...
0
votes
1answer
11 views

Pagination not working in custom post type. Help

I am currently working on an eCommerce project where I am coding a non-WooCommerce dependent theme for eCommerce. The current problem with me is, I am coding archive-product.php which is a custom post ...
1
vote
1answer
789 views

Custom Loop Using Shortcode in Custom Page Template

I am trying to output a custom loop created using shortcode in a custom page template. Here is the code I am using to generate the shortcode: function archive_sc( $atts ) { // Attributes ...
0
votes
2answers
981 views

How to filter get previous post function by meta value DESC and post date DESC?

My loop displays featured posts and then posts in reverse chronological order. However when I use <?php echo get_previous_post(); ?> it grabs posts in reverse chronological order. How do I ...
0
votes
1answer
35 views

Change date format

I am using wordpress for an integration with an recruitment software. Now i am having an issue with an 'endDate' slug. The date format seems to show up as yyyy-mm-dd. How can i change this format to ...
0
votes
1answer
555 views

Multisite redirect loop for a single www domain

I have been using WordPress multisite for several years without a problem. At some point in the last few days one of my many multisite domains is stuck in a redirection loop. The domain is http://...
1
vote
2answers
999 views

Best way to assign post position in a news site homepage? (no categories, no sticky posts)

I'm currently redesigning a local news website. The old design used a whole lot of categories to handle the position of the content in the static homepage as in "top news", "middle box", "left box" ...
0
votes
1answer
2k 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'...
1
vote
3answers
2k views

Displaying Custom Posts on a Page

I have created a page template and custom post type 'pa' that I want to display on the page template. I have the template created, also made archive-pa.php, single-pa.php My template: page-pa.php ...
0
votes
1answer
828 views

Remove posts_orderby filter then add it back in

I'm using remove_all_filters('posts_orderby'); to remove the order for a query. For a query further down the page I need the filter back. How do I add it back in?
0
votes
1answer
1k views

How to Pass Current Taxonomy Terms into new WP_Query?

On my single portfolio pages, I want to add a "See more from this category" section under the post. Here is my code that checks for the single CPT and creates the new query: add_action( '...
0
votes
0answers
67 views

Duplice post with standard WP loop - fixed by using query_posts() instead

I have an index.php file on a website designated as the blog page. I have an archive.php file which handles all the subsequent category pages. I ran into an issue on the archive page, where for one of ...
0
votes
3answers
4k views

Wordpress with woocommerce custom query

I am new to wp dev and trying to figure out how to replace or change the query woocommerce makes that shows all my products on any archive page, or page that shows my list of products, not sure what ...
1
vote
1answer
22 views

Use object in template part

I try to use a template part in my loop. <?php foreach ($categories as $category) { get_template_part( 'temp-parts/loop/blcnr_loop'); } ?> In the template part I call the object <?php ...
0
votes
0answers
17 views

Woocommerce loop - remove hidden products

I've regular woocoomerce archive page. Products that should not be shown, are not shown, which is good. Now, the problem is that WooCommerce's default content-product.php template is doing checks like ...
0
votes
2answers
1k views

How to sort (orderby) a query done by a template function before the 'foreach' loop?

How can I sort an array of elements being hold on a query done by a template function, just before the output starts on a foreach loop? I wanted to order my elements by the Post Title. Here is my code:...
0
votes
2answers
655 views

have_posts() return false on single post

I'm a little bit confused with the use of the Loop. This is my first theme and i just use index.php currently to display all my pages. It works fine for pages but have_posts return false when i try to ...
0
votes
1answer
773 views

Loop to display ONLY custom taxonomy parent information

I'm looking to display only the top level categories from a custom post type taxonomy I've created... product-category. I'm hoping to pull the following data into a loop: Category title (the_title())...
0
votes
1answer
1k views

How to use `foreach()` in ajax call

I have written a code for retrieving data from the database using the ajax for WordPress. The following code is the one written in the functions.php. The code is for getting the id and names of ...
0
votes
0answers
22 views

Is this so hard to do? Product gallery slider on archive pages [duplicate]

I have tried like 1000 diferent methods and the best thing I got was this: With this code: //* Add gallery thumbs to woocommerce shop page add_action('woocommerce_shop_loop_item_title','...
1
vote
1answer
9 views

Wordpress Loop - Not returning projects in specific category

I am attempting to simply pull in all projects in a specific category (e.g. 'websites' or 'featured'). When using: $args = array( 'post_type' => 'project', 'category_name' => 'websites', '...
1
vote
1answer
1k views

Order archive results by post id in custom taxonomy template

My theme's archive template uses this for the loop, <?php if (have_posts()) : while (have_posts()) : the_post(); ?> Seems to be ordered by post title but I need them ordered by the post id. ...
0
votes
1answer
387 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
889 views

List active taxonomy terms

I'm working on tweaking a template which has a filterable masonry layout. I made a taxonomy-categories.php and for the filtering I need the terms of the active taxonomy. The template which I'm using ...
0
votes
1answer
652 views

Limit article to 100 characters. Can't use the_excerpt…

I've been struggling with this for a long time... I want to limit article lenght to 100 characters and after 100 char. limit, add at the end '...' linked to a single post (like wordpress's <!--more-...
1
vote
1answer
684 views

angularjs not displaying all posts

I learned about angularjs today and I am trying to create a page for my search results so that I can be able to create facet filters. Currently I have a page template with the following code -- <?...
1
vote
1answer
689 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 ...
1
vote
0answers
24 views

Filter the loop by categories using checkbox form

I feel I'm close in solving this issue but kinda hit a wall. I have a loop on the examlpe.com/blog site and I'd like to be able to filter it using the category checkboxes. Here is my loop <h3 class=...

1
2 3 4 5
64