The core of the WordPress query, the loop offers an easy way to access post information and display it on your website.
1
vote
2answers
518 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' => ...
1
vote
1answer
791 views
Show scheduled posts in archive page
I'd like my archive.php page's daily view (is_day) to display scheduled posts (post_status=future). For example, if I go to mysite.com/2011/05/20 I would see all posts scheduled to appear on May 20.
...
1
vote
2answers
256 views
How do I display the function the_content in this loop?
I have this loop in my wordpress site which displays the latest posts with their titles, I want to display the post content after the title. I normally retrieve it with the function get_the_content ...
1
vote
1answer
25 views
Reverse chronology of post listing
I"m working on modifying a theme that is based on 2010.
I want to make the posts on this blog display earliest to oldest, but I don't see how to do this in the theme:
I understand I need to add . ...
1
vote
3answers
45 views
Force index.php have_posts() loop to exit if no sticky posts found
I'm currently using the code below to list sticky posts on my index.php.
However, when no sticky posts are present, its loading the latest posts (up to the number specified in "settings > reading > ...
1
vote
2answers
47 views
Knowing the total number of posts before to get into the loop
Is there a way to know the total number of posts before the loop starts? I'm thinking in use two loops. The first will do the counting, while the second one will handle the content. However, I don't ...
1
vote
1answer
357 views
Is there any need to use both wp_reset_postdata and wp_reset_query together?
Is there any need to use both wp_reset_postdata() and wp_reset_query() together?
Is it a case that I would pick one of the two functions; is there any point in doing this after a query :
...
1
vote
1answer
2k 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 ...
1
vote
1answer
470 views
Exclude custom taxonomy tag from loop
I have the following code at the beginning of a loop:
<?php query_posts('showposts=3&cat=84'); ?>
<?php $posts = get_posts('category=84&numberposts=3&offset=0'); foreach ($posts ...
1
vote
2answers
91 views
Help with Changing loop.php?
I'm trying to edit the loop so if its on category ID 60 it displays "Photos" instead of "Blog".. how do I do this?
blog
<?php ...
1
vote
2answers
1k views
List all posts in Custom Post Type but group dynamically by Custom Taxonomies
I have a custom post type named "Resources" which has a Taxonomy named "Types."
I have it manually pulling each term which isn't the most elegant solution and every time there is a new term added, I ...
1
vote
2answers
2k views
How to use a custom post type as front page?
I would like to set a site's front page to be a single post from a custom post type. I have been able to alter the request for my front page to a Custom Post Type archive with the following code ...
1
vote
1answer
6k 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() == ...
1
vote
2answers
2k views
In a foreach loop, how do I target the last item in the loop?
I have the following code to do a foreach loop, I want to target the last item in the loop (e.g if it's looped over 3 events I want to target the 3rd event) to do something slightly different with the ...
1
vote
3answers
304 views
Using the loop inside admin
I have the following issue:
I am creating a custom-meta-box for the user to add custom fields in a friendly way.
I want to generate a drop-down box with all posts that fall under category 10.
I have ...
1
vote
3answers
477 views
How would I go about listing only unattached media in say a sidebar?
I have a client who uses PDF files for their newsletter, I don't think that this is a good idea personally, but it's not negotiable. They have a news page where they put real time news and they'd like ...
1
vote
2answers
512 views
Pagination gives extra page with no results
I'm trying to implement pagination on a category page. The pagination is working, but now for some reason the pagination plugin I'm using is noting one extra page of results, when that page is ...
1
vote
3answers
980 views
Check if post belongs to any category
In my homepage loop, I have something that will show which category the post is in. It will say something like "Posted 4 hours ago in Sports by ...". However, when there is no category set, it will ...
1
vote
2answers
848 views
category__not_in — anyway to use category name instead of id?
I would like to exclude categories from the loop using the "name" instead of the "id", since the ID can change when using new databases. The name however will always be the same.
Is this possible?
1
vote
2answers
33 views
2 Loops, Only Displaying 1 Loop in Both Loops
I have 2 loops, movie trailers and gaming trailers but gaming trailers is displaying under both Movie Trailers and Gaming Trailer. Each loop displays the post tagged with either Movie Trailer or ...
1
vote
2answers
67 views
Query for posts in 2 taxonomies
I am currently using the following code to display a list with links to posts in a specific CPT and taxonomy:
<?php
$custom_terms = get_terms('videoscategory');
foreach(array($custom_terms as ...
1
vote
3answers
101 views
How to add element after every post in the loop, but not the last one
I have a pretty common loop:
global $wp_query, $wpdb;
if ( have_posts() )
{
while ( have_posts() )
{
the_post();
get_template_part(
'template_parts/content'
...
1
vote
1answer
502 views
Insert image or ad script after 3 posts using the loop
There are many scripts/hacks out there to insert ads into the middle of the post (after 'x' number of paragraphs), however I haven't found a good enough script that can do the above.
This is the ...
1
vote
1answer
876 views
Get Custom post with ID
How do I get a custom post by its ID? I want to display a single post from custom post using its ID. I tried 'post_type' => 'homepage', 'post_id' => '717' but it didnt work.
Thanks
1
vote
2answers
708 views
Order posts by custom field and if custom field is empty return remaining posts
I have an archive page ordered by a numeric value in a custom field. This returns the ordered posts correctly, but does not display posts that don't have a custom field.
$paged = ...
1
vote
1answer
47 views
Check to see if specific loop has less than certain amount of posts
I'm looking for a way to check how many posts are returned by a specific loop. So if I have a loop like this..
<?php
$featured_post_id = get_the_ID();
global $post;
$args = array('cat' => ...
1
vote
2answers
155 views
How to speed up a wordpress function with multiple loops?
I am a PHP novice and wrote this function. It is an alphabetical navigation which shows only the letter that have posts in both that letter and the currently filtered "genero" taxonomy term.
I use ...
1
vote
2answers
130 views
Combining the_excerpt with the_content
I have some html:
<div class="container">
<p class="accent">The first paragraph...</p>
<p>The rest of the article...</p>
</div>
I'd like to put "the_excerpt" in ...
1
vote
1answer
314 views
Facebook “like” open graph meta in header.php
I would like to add open graph meta tags to my header.php, but can someone explain how this works if header.php comes before my loop with the relevant information??
<meta property="og:title" ...
1
vote
2answers
88 views
Different style for most recent article
I'd like to make my most recent article display a large with a larger thumbnail and with more content, while the rest of the posts in the loop show a small thumbnail and only the title with no ...
1
vote
1answer
1k views
Dynamically excluding current page id
I'm attempting to create a "related posts" section on pages using query_posts. I'm wanting to use this simply because we want to show random posts from one category on one page, so a plugin would be ...
1
vote
4answers
561 views
Using one WP_Query object within the loop of another WP_Query object
I'm creating two different WP_Query objects, one for each of two different post types I'm using. In creating my output, I'd like to loop through one of the objects, and at the same time loop through ...
1
vote
1answer
235 views
Custom loop with conditional statement to separate each terms
Let's say for example:
I have a custom taxonomy called "fruit", which has 3 terms "apple", "orange", and "grape". So in order to get all the posts within all these three terms, I would :
$args = ...
1
vote
2answers
386 views
Single page site (Wordpress) including posts
I'm creating a single page site and obviously want to include the blog posts. I'm currently looping through the pages and using the_content() and the_title() to display them. However, the_content ...
1
vote
2answers
725 views
How to determine if an admin is logged in outside the loop
I need to be able to tell if an admin is logged in ouside of the loop.
This is needed for some php files that are part of a WP site but do not use require( '../wp-load.php );
What I need to do is ...
1
vote
2answers
108 views
Finding posts containing matching array elements in a meta field usign WP_Query
I have a metafield, that contains a series of options and writes the results to an array in a single meta field:
array([0]=>'First',
[1]=>'Second',
[2]=>'Third',
);
I find ...
1
vote
1answer
107 views
Varying Search Result Pages
I have two different kinds of search results on my site and I'd like to change the look of the search result page entirely. I've played around with the search form a bit but I'm unsure how to force it ...
1
vote
1answer
540 views
Custom excerpt function re-factoring
This may be more of a php best practices question, but here goes...
I am using a custom excerpt trim function:
function new_wp_trim_excerpt($text) { // Fakes an excerpt if needed
global $post;
...
1
vote
2answers
306 views
Why would in_category only return one post in a specific category?
So... what I'm trying to do is simple - get the post content for all posts, but only in a given category. Simple - filter the loop using in_category. So I did this (this is actually a stripped version ...
1
vote
2answers
6k views
Get post by page name or slug
I know this is very avant-garde, but bear with me.
I've read that one is able to query a page by the page/post name or slug. I'm trying to do this because I need information from a page with a similar ...
1
vote
2answers
664 views
Adding 'current_post_item' class to current post in the loop
I'm using a loop in the sidebar of my site to show all the posts that are in that category.
Now I'd like to include a 'current_post' class to the current post that is being displayed to style that ...
1
vote
1answer
1k views
Using the Loop to show all levels of subpages under a parent page? Halfway there
I have a need to make the Loop run through all of the children of a parent, all of the children of each child, etc. The reason I need the Loop instead of a listing tag like wp_list_pages is so that I ...
1
vote
2answers
320 views
Multiple loops on the same page removing post tags
I am trying to use two loops on my page, one to get the current page's content and so on, and another to get all of the posts of a specific category.
When I do that, all of the tags for the current ...
1
vote
1answer
2k 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)?
1
vote
1answer
792 views
Is it possible to query_posts using post__in and then Loop through them in the ordered they were queried?
query_posts( array ( 'post__in' => array( 5, 76, 21, 56, 3 ) ) );
I'd like to query the Loop using post__in and a set Wordpress IDs. I'd then like to run through the Loop in the exact order of ...
1
vote
1answer
1k views
Custom Post Type Loop within Shortcode
I'm really at loss as to why this isn't working:
I am using a shortcode to display a query on a custom post type + taxonomy, this is the segment of it:
// - arguments -
$args = ...
1
vote
1answer
1k views
How to insert content from another Custom Post type into Post?
Say I have a custom post type called "Performers". This gets populated with different bands/performers. These posts have a featured image as well as custom fields (mp3 file, facebook link, myspace ...
1
vote
3answers
364 views
get the image of the post
Im running 'the loop' and I want to get the image of the post (in original size - not thumbnail), how do I do it?
thank you.
1
vote
3answers
4k views
How to Change Loop to Order Posts by Views (using wp-postviews plugin)
I hope somebody would be kind enough to help. I currently have a page that orders all of the posts by comment count, but I want to change the loop to order the posts by view count. I have installed ...
1
vote
1answer
349 views
How can I show the post thumbnail from the most recent of a certain post type, in widget?
I'm using the excellent PHP Code Widget plugin, and want to create a widget that displays the post thumbnail (aka featured image) for the most recent 'project' post. Here's the code I have so far, but ...