Skip to main content

All Questions

Tagged with or
Filter by
Sorted by
Tagged with
144 votes
5 answers
136k views

How to fix pagination for custom loops?

I have added a custom/secondary query to a template file/custom page template; how can I make WordPress use my custom query for pagination, instead of using the main query loop's pagination? Addendum ...
Chip Bennett's user avatar
  • 55.1k
139 votes
15 answers
610k views

How to get URL of current page displayed?

I want to add custom PHP code to ensure that whenever a page on my site loads in my browser, the URL of that page is echoed to the screen. I can use echo get_permalink(), but that does not work on ...
cag8f's user avatar
  • 1,997
78 votes
3 answers
240k views

Counting the posts of a custom Wordpress loop (WP_Query)?

I tried tplacing this: <?php $count = count($custom_posts); ?> <h2><?php echo $count; ?></h2> at the end of the loop: <?php if ( bbp_get_forum_title() == '...
wyc's user avatar
  • 3,897
43 votes
5 answers
34k views

Pagination not working with custom loop

I've got a custom loop that I'm using to display some Real Estate listings that will be available within 60 days. I'm calling it with the following function: <?php $sixtydays = date('Y/m/d', ...
nurain's user avatar
  • 557
39 votes
3 answers
217k views

Meaning of "if ( is_home() && ! is_front_page() )" snippet?

I see the following code a lot in index.php files. I understand that is_front_page() returns true when viewing the Site Front Page (whether displaying the blog posts index or a static page), while ...
olliew's user avatar
  • 537
32 votes
9 answers
78k views

Get excerpt using get_the_excerpt outside a loop

I have a code that call get_the_title() and it works, but get_the_excerpt() return empty. How can i make it work? This code is inside a plugin called "WP Facebook Open Graph protocol". Here's the ...
ariel's user avatar
  • 495
31 votes
1 answer
35k views

How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]

I read this question but it wasn't what I was looking for exactly. I'm new to Wordpress and a little confuse with the functions and everything. How can I get the metadescription in the loop for each ...
sambellerose's user avatar
28 votes
6 answers
57k views

How do I exclude a custom taxonomy from the post loop

Is there a simple or easy way to exclude all posts from a custom taxonomy in the loop? I've been looking high and low, and neither SE, SO or Google seem to have a straight answer. I know it can be ...
Thomas's user avatar
  • 487
27 votes
4 answers
44k views

Can i merge 2 new WP_Query($variable) 's?

I am running a multisite network and i have setup a sql query that uses swith_to_blog(); and queries the posts. Is there a way that i can declare the query inside a new WP_Query and actually merge ...
Rory Rothon's user avatar
27 votes
4 answers
36k views

Manually set global $post vars with an ID, in order to use template tags

I have a function retrieving ID's of posts by very specific means. I need to be able to set the global $post in order to use functions like the_content(), which does not allow an ID as a parameter. ...
Mild Fuzz's user avatar
  • 4,190
26 votes
11 answers
72k views

Get post content from outside the loop

Is there a way to get the content from another outside the loop? The ID is 302 and I need to display the content of that on another page.
Rob's user avatar
  • 1,406
26 votes
3 answers
9k views

Can I force WP_Query to return no results?

I'm working on a website with a search feature that allows users to search through a lot of post meta. There is a specific search pattern that I would like to forcibly return no results for. The ...
somebodysomewhere's user avatar
26 votes
2 answers
31k views

Getting only direct child pages in WordPress with get_pages

I am trying to fetch all direct children of a page. But I am getting all children and grand children as well. Any ideas? PHP Source: $args = array( 'child_of' => $post->ID, '...
lejahmie's user avatar
  • 373
25 votes
4 answers
51k views

Why should I put if(have_posts()), is while(have_posts()) not enough?

I have a question about "the loop". <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your ...
ironsand's user avatar
  • 559
25 votes
4 answers
137k views

Get the children of the parent category

I'm trying to get all the children categories to display in this loop but I'm struggling with the code. This is what I have so far. <?php $args=array('orderby' => 'name', 'order' => 'ASC'); ...
Chris Da Sie's user avatar
25 votes
2 answers
15k views

Resetting post data to previous loop in nested loops

I'm trying to use nested loops with the posts to posts plugin. The loops both work, but the problem arises after the second nested loop ($issue). I want to access the $publication loop again, but the ...
kdev's user avatar
  • 863
24 votes
10 answers
94k views

Display featured products through custom loop in woocommerce on template page

I would like to display 6 featured products from my woocommerce store on my home-page.php template. After some researched I found that the right way to do this was through a custom loop,( I do not ...
steamfunk's user avatar
  • 645
24 votes
2 answers
59k views

Query multiple custom post types in single loop

I'm aware there are several other posts that cover similar ground to what I'm about to ask. I have three custom post types running, in addition to 'posts'. I want to run a loop that pulls all posts ...
dannyw24's user avatar
  • 451
23 votes
3 answers
15k views

Split Content and Gallery

Is there a way to split up the post content and the gallery short code. I want to display the gallery outside my normal content no matter how or where it is placed. I can use this to get the shortcode ...
Howdy_McGee's user avatar
  • 20.8k
23 votes
6 answers
59k views

Print Current Post Index number within Loop

I'm working on WordPress where I have following code to get posts within loop. <?php $posts = $woo_options['woo_latest_entries']; query_posts('post_type=...
MANnDAaR's user avatar
  • 363
23 votes
1 answer
2k views

Should we trust the post globals?

@toscho left a comment to this answer which had me thinking again. How much trust should we have in the global scope, specially regarding the post globals like $post? So what? The global variable ...
Pieter Goosen's user avatar
22 votes
7 answers
64k views

Display all posts in a custom post type, grouped by a custom taxonomy

I’m working on a member page where I use a custom post type with a custom taxonomy. My custom post type is called member and my custom taxonomy is called member_groups. I want to list all the members ...
Mestika's user avatar
  • 770
22 votes
1 answer
8k views

Some doubts about how the main query and the custom query works in this custom theme?

I am pretty new in WordPress theme development and I'm not so into PHP (I came from Java and C#) and have the following situation in this custom theme As you can see in the homepage I first show a ...
AndreaNobili's user avatar
19 votes
8 answers
66k views

How to get Author ID outside the loop

I can't get the post author ID outside the loop to make the get_the_author_meta work. So far I've tried different approaches: 1. $author_id=$post->post_author; 2. global $post; $author_id=$post-...
Marce Castro's user avatar
16 votes
4 answers
115k views

Get post count of current loop when using multiple queries on one page

I'm trying to get a count of the current posts inside of a loop. I'm using multiple loops on one page in my theme. So far I have: $my_post_count = $wp_query->post_count; But when I print $...
pwbred's user avatar
  • 548
16 votes
3 answers
77k views

How to get posts published between a date and today?

Is it a way to get posts published between a date and today with query_posts() ? Example : All posts published since 2012-04-01 Thanks EDIT : How to add the filter date on this Query Posts ? ...
Steffi's user avatar
  • 765
16 votes
3 answers
15k views

Have different number of posts on first page

I need to have a different amount of posts per page on the first page that on the other pages. For example, this is what I need Total posts: 6 First page: showing 3 posts Following page: showing 2 ...
norixxx's user avatar
  • 365
14 votes
5 answers
93k views

Redirect loop when trying to login to /wp-admin/ [duplicate]

Stuck in an infinite loop when trying to log in to my wordpress site. I type in the URL/wp-admin and then it loops me back to the regular website, not the admin login page. I have tried with http ...
Rebecca's user avatar
  • 141
13 votes
2 answers
14k views

How to check if I'm on the last page of posts?

I want to display some text on the last page that isn't displayed on the other pages. For example, on category pages: url.com/category/categoryname/page/6 or last page of all posts listed on the ...
user7880's user avatar
  • 131
12 votes
1 answer
20k views

Multiple WP_Query loops with Pagination

There are a few other questions about this (and WP_Query pagination seems to be a huge question for a lot of people) so I'm trying to narrow down exactly how to make it function. I'm able to create a ...
Cory's user avatar
  • 223
12 votes
1 answer
16k views

How can i display the content in plaintext

i want to display my excerpt in plaintext. How can i do this? This is my Snippet where i display the content: <?php the_content(__( 'Weiterlesen &rsaquo;','okay')); ?> How i change the ...
ScienceNoob's user avatar
12 votes
3 answers
15k views

Display all posts starting with given letter?

I'm trying to build Wordpress based dictionary, basically it will have 26 pages (one for each letter): A B C ... X Y Z And every page will display all posts starting with given letter, so after ...
Wordpressor's user avatar
  • 5,051
11 votes
1 answer
11k views

Is it necessary to reset the query after using get_posts()?

Is it necessary to reset the query after using get_posts() ? I have been looking at this page and I don't see any reference to get_posts() ... I can't make it out for sure from this page either. I ...
byronyasgur's user avatar
  • 3,032
11 votes
1 answer
28k views

Sort pages in loop by admin's page attributes order field?

Is it possible to sort pages in the loop using the admin's order field (under page attributes)?
Ryan's user avatar
  • 515
11 votes
5 answers
31k views

How to split a loop into multiple columns

If I have a loop running from a category query like : <?php $the_query = new WP_Query('cat=1&showposts=50&orderby=title&order=asc');?> <ul> <?php while ($the_query->...
zac's user avatar
  • 650
11 votes
1 answer
20k views

How do you get the count of posts in an archive page?

I have a custom posts archive page of the type archive-my_custom_post_type.php and I am using the "standard" loop which consists of the ever-so famous <?php if(have_posts()) : ?> <?php ...
Florian Segginger's user avatar
11 votes
1 answer
16k views

What is This esc_html_e() i wordpress php?

why do developers use <?php esc_html_e() >? in 404 pages, what does it mean, how does it works?
TheDose's user avatar
  • 198
11 votes
2 answers
14k views

Using a custom WP_Query with get_template_part loop

I have a query for a custom post type: <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $books = new WP_Query(array( 'post_type' => 'wiki', 'posts_per_page' => '...
passatgt's user avatar
  • 3,401
10 votes
2 answers
21k views

Is there any difference between the_title() and echo get_the_title()?

Just a small question. Is there any difference in using <?php the_title() ?> or <?= get_the_title() ?> Yeah, I know somebody can consider using short echo tag a bad practice, I just ...
Boykodev's user avatar
  • 337
10 votes
1 answer
11k views

AJAX with loop filtering categories

I've been researching on how to make my loop with AJAX. I found some codes online and modified some parts but I can't seem to get it to work. This is my code for the loop: <article id="main" ...
madmanali93's user avatar
9 votes
1 answer
15k views

group search results by post type?

My site has 3 unique post types: Default Blog posts ("post") custom type "lesson" custom type "series" When the user searches the site, I would like pertinent results from all 3 post types to show ...
tdc's user avatar
  • 271
9 votes
1 answer
58k views

how to override woocommerce specific loop or archive-product.php [closed]

so far while my woocommerce theme loop through all products in shop page i'm trying to customise and add few bootstrap classes to style it in a prober way since default styles generated causes layout ...
OT AMD's user avatar
  • 95
8 votes
12 answers
63k views

remove <p> tags from the_content

I've got a post format of Image, and I am running into an issue where the image is being wrapped by a <p> tag. I want to get rid of that tag (specifically on the single.php version) of those ...
Jon Mitten's user avatar
8 votes
2 answers
13k views

Show posts without term

I am working on a product page where I show reviews from my post type 'reviews', if the product page title matches with my term from the taxonomy 'review-product'. Example. Product page title: ...
Robbert's user avatar
  • 1,265
8 votes
2 answers
42k 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;
Robbert's user avatar
  • 1,265
8 votes
2 answers
7k views

WP_Query vs get_posts

I have read a number of questions on SE regarding these but I still can't figure the exact difference wrt usage. Would it be true to say that I would probably use WP_Query for the majority of ...
byronyasgur's user avatar
  • 3,032
8 votes
2 answers
46k views

Make loop display posts by alphabetical order

With this loop I am displaying single posts on an archive page. The posts are being sorted by the category 'Banks'. In addition to that, how can I display them in alphabetical order? I've tried using ...
ael's user avatar
  • 81
8 votes
5 answers
20k views

the_title() shows title of the first post instead of the page title?

I'm occasionally facing this problem and not sure what causes it, any ideas? <?php get_header(); ?> <div class="content" role="main"> <h1><?php the_title(); ?>&...
Wordpressor's user avatar
  • 5,051
8 votes
2 answers
3k views

Do I need to use The Loop on pages?

I'm writing my first WordPress theme and have a question about the use of The Loop in page templates. The page templates I've looked at all follow basically the same pattern (example from Twenty ...
Jamie Ide's user avatar
  • 183
8 votes
1 answer
6k views

How can I fetch loop of post titles via AJAX?

I have a list of the most recent post titles in sidebar.php. Here is an example of how that code looks: <?php $args = array('posts_per_page' => 20); ?> <?php $sidebar = new WP_Query($args)...
Sahas Katta's user avatar

1
2 3 4 5
67