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

learn more… | top users | synonyms (3)

-1
votes
1answer
19 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) ...
1
vote
1answer
32 views

A snippet after every image

folks. I need to put a piece of code after every post image (post attached image). it's something like this: <img class="alignnone size-full wp-image-3079" src="imgurl.jpg" alt="02" width="2592" ...
1
vote
0answers
24 views

Showing random content / pictures from earlier posts in a sticky post?

I have a sticky post on my wordpress blog, in the beginning. I would like to place some random content in it, by simply replacing some HTML in the post content. The random content would come from ...
-1
votes
0answers
24 views

Get posts that matches specific terms of multiple custom taxonomies

I'm working on a page that show a lot of products. My structure is Product (custom post type) -->Brand (custom taxonomy) ------>Brand A (custom term) ------>Brand B (custom term) -->Department ...
2
votes
1answer
17 views

How to order category.php loop by 'meta_value'?

So I have a basic loop on category.php that displays all posts from the specific category, like this: <?php if (have_posts()) : while(have_posts()): the_post(); ?> <a href="<?php ...
0
votes
0answers
11 views

modifying variables passed to the Wordpress LOOP, with IF/THEN?

good evening, i'm trying to make my coding as modular as possible. my site uses three different LOOPs, each to accomplish a different task with my posts/pages, and i've got each loop on its own file, ...
0
votes
1answer
15 views

include(locate_template) messing up the loop

So, I've developed a one page theme that pulls in child pages of the parent in order create the layout. I also have it set up to pull each sub pages page template and display the content accordingly, ...
3
votes
3answers
37 views

Why does the_content not work like others for a set post id?

Here's something odd, I want to print out a certain post on any page request, if you have a constant $idnumber of your favorite page/message, then add: $GLOBALS['post'] = get_post( $idnumber ); ...
0
votes
1answer
29 views

How to hook into <head></head> container

I want to add my own <meta /> tag inside the <head></head> container on every page or post within the loop(). Is that possible? What hook(s) should I use for that?
1
vote
2answers
46 views

get latest 5 posts and a specific post and sort in a specific order

I'm looking for some advice on how to make a gallery of images. it is a particular bit a gallery, because I would show the last 5 post and a fixed post, for a total of 6 posts, in a specific order. ie ...
0
votes
0answers
41 views

Get custom post type's fields in a while loop as variables

I'm working on a page that shows the name of a lot of products (custom post type), and when the user clicks on the name he can see some product information. It's something like this: Main page with ...
0
votes
1answer
38 views

How to provide meta_key array to wp_query?

I'm trying to build a wp_query, so far I've managed to get desired result using following query. $args = array( 'meta_query' => array( 'relation' => 'OR', array( //check if ...
3
votes
1answer
42 views

What is best way passing variables to theme templates and using them different places like widgets?

I have a template file at /parts/template.php which contains a post listing code like, echo get_the_title(); //same lines with my_render_function and i am using it at archive.php with this lines. ...
0
votes
0answers
8 views

Popular posts with Varnish ESI

I am trying to get Varnish ESI to work with displaying the most viewed posts on a new blog I am working on. Here is my current script; In theme file: <esi:remove> <?php get_template_part( ...
0
votes
0answers
14 views

Retrieving category pages from subcategory returns empty sets

I've a category overview page. It shows its subcategories. These subcategories have subsubcategories which are pages too. I'd like to retrieve those (title, permalink and excerpt) but so far my ...
0
votes
2answers
36 views

Exclude duplicated $sticky post from combined loop content

Since Wordpress sticky posts feature allow the post checked as sticky in post publish panel to be placed at the top of the front page of posts. I was also intended to style the sticky post differently ...
4
votes
2answers
40 views

Finding Page Template and Displaying Content

So, I'm building a theme for a client with one page layout functionality. Currently, I'm allowing the user to create a parent page, and the modules within that page are separate pages that will be set ...
0
votes
1answer
26 views

Querying posts from only one category and exluding the latest post

I want to run the loop so that it retrieves posts from only one particular category AND outputs only 4 posts AND excludes the latest one. To query only one category, I found this: <?php ...
3
votes
2answers
53 views

Are there any scenarios where the query_posts may be used?

I feel there is a red button saying "Do not press" below query_posts(). For some time I am trying to demystify this phenomena with very low success to be honest. For example, probable the main ...
1
vote
1answer
26 views

How can i use the same template file with a widget and category loop?

i wrote a widget and i want to use category template which is located in "themename"/template-parts/content.php". <?php // Category.php while ( have_posts() ) : the_post(); get_template_part( ...
3
votes
2answers
65 views

Is `query_posts` really slower than secondary query?

I know the main query is fast, since it gets data after parsing the URL and after WP_Query has been instantiated. We are in OO PHP. But is query_posts really slower than some secondary query that ...
0
votes
0answers
16 views

Exclude Featured Image Attachments from Wordpress Search Results

I'd like my search.php page to show all attachments except featured images (because they appear as duplicates of the posts that use them). I have seen some examples that do this for a query, but ...
0
votes
1answer
20 views

Show one item per category of a custom post type

I'm having a custom type called portfolio with different categories. I want to display all my categories except one. I only want to show one item per category on my page. I'm been busting my butt on ...
0
votes
0answers
17 views

Display Posts in Admin Page

I create a admin page. Now I need to display posts in that page. Should I use WP_Query or get_posts()? (Pagination should be there) Note : I have read When should you use WP_Query vs query_posts() ...
0
votes
0answers
14 views

add date of most recent custom post type

I have a custom post type called products, it is categorized by a custom taxonomy called product_category. I'm trying to have a "last updated on" note on the taxonomy archive pages. I was hoping ...
0
votes
0answers
13 views

How to query post from sub-categories on category archive and display posts?

On a custom taxonomy archive from the taxonomy called 'books' (taxonomy-books.php) I want to list all subcategories that are assigned to the parent category. And then for each subcategory I want to ...
-1
votes
1answer
36 views

Show only posts from todays date [duplicate]

<?php if ( have_posts() ) : ?> <?php // Start the loop. while ( have_posts() ) : the_post(); get_template_part( 'content', get_post_format() ); // End the loop. endwhile; else : ...
1
vote
1answer
19 views

Wordpress Search Results for Multiple Post Types

I want to show both posts and attachments in the search results. Basically, I need something that says if the post has a thumbnail, show it. else show the attachment image (since they don't have ...
0
votes
1answer
12 views

Highlight specific user with custom field value

I'm working on a Wordpress project with some friends from school. But there's a problem with highlighting a user on the website. The idea is to create a 'User of the month' thing. In the user ...
1
vote
1answer
7 views

trouble calling an import class from an action in a plugin before wp_cron executes

I’m using the wp_crontrol plugin to call an action added in my functions.php file which then calls a function in my plugin file. WP gets to my function but can’t call the class, I get this error: PHP ...
-1
votes
0answers
18 views

Wordpress pagination why is this not working? [duplicate]

I got the following code: <main id="main"> <?php // the query $args = array('posts_per_page' => 2 ); $the_query = new WP_Query( $args ); ...
0
votes
0answers
27 views

How can I add pagination to my loop? [duplicate]

That's my current loop: <main id="main"> <?php // the query $args = array('posts_per_page' => 10 ); $the_query = new WP_Query( $args ); ?> ...
2
votes
3answers
38 views

Wordpress loop specific thumbnail size

That's my loop: <main id="main"> <?php // the query $args = array('posts_per_page' => 10 ); $the_query = new WP_Query( $args ); ?> <?php if ( ...
1
vote
1answer
38 views

How can I add pagination and how can I change thumbnail size?

I'm currently learning wordpress development and I try to add pagination which displays a "older"/"newer post" link and the number of the current page at the bottom of the posts. I also try to change ...
-1
votes
0answers
16 views

WordPress category Pagination Not Working After Modify the Loop [duplicate]

I modify the category page loop as following code. Now Pagination not working. Why is that? How to correct it? Note : Even though there many similar questions on this site any of them not solve the ...
4
votes
1answer
32 views

Executing Queries in tag.php

I'm probably being dense, but I can't seem to figure out what the issue here is. The site I'm developing uses a custom loop, with a query that excludes any posts ticked as archived. The reason I ...
0
votes
2answers
19 views

Call wp-blog-header.php header without performing a wp_query

I have setup .htaccess to map a custom url to a custom php script. This page is not part of wordpress, but i want it to use the wordpress theme. At the top of the script I load up Wordpress. And from ...
0
votes
1answer
21 views

Attachment Metadata inside of Loop

Basically, I'm trying to call attachment info to display withing a loop, for use in an image gallery. I know I need to use wp_prepare_attachment_for_js($attachment_id) but I can't seem to get anything ...
1
vote
1answer
22 views

How can I show custom fields in the loop only to specific user roles?

I've inserted this code in the loop (in single.php): <span style="font-size:16px"> <strong>Currently reading:</strong> <?php the_field('book_name'); ?> (<?php ...
0
votes
0answers
13 views

Sticky posts with conditional taxonomy check

I have two different taxonomies with the same terms. so let's say: Places: Russia, India, Jamaica. Sticky Places: Russia, India, Jamaica. Now i want to create a loop which checks if a post has two ...
0
votes
1answer
21 views

Show modified time if post is actually modified

I want to display post updated time only if post is modified, I am using function the_modified_time() . So I just read about that there is if statement that can be used to check if post is even ...
0
votes
2answers
24 views

Display post formats differently on index.php (loop in function)

I'm a newbie-- please bare with my ignorance here. I've been trying to read other questions about this but so far I can't wrap my head around this. I'm hoping to display post formats differently on ...
0
votes
2answers
18 views

Random post link messes up the loop

I have this code that generates a link to a random post in my blog: <?php $posts = get_posts('orderby=rand&numberposts=1'); foreach($posts as $post): ?> <a href="<?php ...
1
vote
2answers
32 views

how to merge a WPQuery array with a PHP array and use the Loop to Output the result

I have a mostly normal WPQuery (getting 3 post types) for use on a Blog page. This works great. Client wants Instagram images to be included and ordered by date. I have all the instagram code setup ...
0
votes
1answer
28 views

Wordpress Request Post All Post ID in a Loop? [closed]

I would like to ask if there's a way on WordPress to get fetch all of the page's Field?... I am using a Advance Custom Field Plugin and would like to fetch data's from fields inputted over those ...
6
votes
3answers
263 views

Remove the Homepage Query

I have a homepage displaying the home.php template, containing 2 sidebars with widgets in them. The main query still pulls in the standard 10 posts, but since I'm not displaying these, I'd like to ...
-1
votes
1answer
13 views

Multiple loops using next_posts_link & previous_posts_link

I have more than one loop in the same page and they are working perfectly, but the problem comes up when I try to use next_posts_link & previous_posts_link for a specific div. Example: <div ...
0
votes
0answers
36 views

WooCommerce: Making a loop create divs of categories, with category products inside

I have a php/wp script written which in theory should print a div with a category name, description, and all of its products inside. The code looks like this: <?php $args2 = array( 'taxonomy' ...
0
votes
2answers
71 views

How to change post count in wordpress loop?

Hey I am attempting to customize my WordPress post loop to create different post styles for a certain set of posts. For example the first three posts would be styled in it’s own way, the next four ...
0
votes
1answer
48 views

Loop 1 user randomly

At the moment I am using wp_user_query to loop users from a specific role(leden) on a webpage. For the overview page this is working fine, but on my homepage I want to feature one random user. I was ...