get_posts() is a function for creating multiple loops. It retrieves a list of latest posts or posts matching criteria.
1
vote
0answers
229 views
How to reload a select box of posts dynamically?
I'm using custom meta boxes for a project. I have created a custom taxonomy (select box) and I have another select box populated with Posts. I need to only load the posts based on the selection of the ...
1
vote
1answer
470 views
get_posts with meta_compare='LIKE' not working
I am using the following code:
$tolettpe = "Sale";//default
if($_REQUEST['tolettype']) $tolettpe = $_REQUEST['tolettype'];
else if($_REQUEST['srch_type']) $tolettpe = $_REQUEST['srch_type'];
$args = ...
0
votes
1answer
57 views
get_query stops working after post filter
I'm currently trying to set up some filters for a custom post type within my admin. The custom post type is 'players' and I'm filtering them by another custom post type 'teams'.
To create my ...
0
votes
1answer
214 views
Display a random customposttype2 excerpt in single-custompostype1.php that shares same taxonomy
OK - Looked everywhere for this one.
Details:
Custom Post Type #1 = 'product' > registered taxonomy 'productranges'
Custom Post Type #2 = 'testimonial' > registered taxonomy 'testimonials'
Both ...
1
vote
1answer
155 views
Get posts inside Get terms problem
i have a get_terms which loads correctly.
inside of it i have used get_posts. then using get posts i am
trying to get each post tags (and count <= not currently inside this script)
<?php
...
0
votes
1answer
124 views
What is the p parameter in a get_posts() parameter array?
I've seen code that looks like this:
get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment'));
What is the definition of the p parameter and is it documented anywhere? I can't find ...
0
votes
2answers
112 views
Sorting posts by specific order
I have a custom post type and I want to be able to control the order that the posts are displayed by defining the order in an array, and then checking the posts meta_value against the array to see ...
0
votes
1answer
71 views
Get first <ul> of post? [closed]
I have a What's New page where I continually update the page like this:
June 21
Some news about my site
Here's the second new bullet point
Now I'm not sure of any other way to archive my 'Change ...
1
vote
1answer
516 views
latest 5 posts using switch_to_blog loop
im sure i must be doing something wrong and would really appreciate a little help.
I am trying to loop through all of my Sub Dir "Multisite" blogs using switch_to_blog, below:
global $wpdb, ...
1
vote
2answers
85 views
Why is querying posts messing up my pages?
I am working on a theme at the moment and I have set up a post template.
This post template is linked to some custom post types.
When I query_posts for my post type on the actual post template ...
1
vote
1answer
236 views
How can I paginate a list of related posts?
My client's home page displays a paginated list of posts with thumbnails. Each list item, when clicked, navigates to a single post or page, and then uses a separate query to generate the same list of ...
1
vote
1answer
290 views
If meta key exists in get posts function otherwise create it
The following code fetches posts with the meta key home telephone numbers.
$metas = '';
$args = array(
'numberposts' => 1,
'post_type' => 'electors',
'orderby' => ...
0
votes
2answers
413 views
Add filter to get_posts
So I am attempting to filter out certain posts in the get_posts call. Essentially, I want to be able to specify a certain block of posts, and only get the posts that correspond with the block. Right ...
0
votes
1answer
290 views
Can't sort get_posts by post_mime_type
I'm trying to run a query to get all attachments and I'd like to sort by the post mime type. This query isn't working. Any ideas?
$query_args = array(
'post_type' => 'attachment',
'numberposts' ...
0
votes
2answers
451 views
get_posts displaying wrong permalink for “continue reading” link
I lifted the "continue reading" link functions from the Twenty Eleven theme and for the most part, it is working (works in RSS feeds).
I created a shortcode to display the latest post on the front ...
0
votes
1answer
56 views
Use get_posts() with 'post' and 'page' queries at the same time?
I'm trying to grab all posts which are 'posts' and not in category '3' and '5' and which aren't 'pages'. Is this possible to do using one single get_posts()? Because I'm querying both actual posts and ...
0
votes
3answers
94 views
Delist entries in the_loop
I am trying to add a delisting feature to my WordPress network. Posts which are delisted would not appear in post lists, but would still be visible if accessed directly.
I've written a plugin that ...
2
votes
2answers
119 views
How to get 4 Posts after the 5 most recent ones
Well, I think the question might be a bit confusing. But well, I want to get the recent 4 posts, ignoring the first five recent posts. So in short the sixth, seventh, eighth and ninth - most recent ...
0
votes
2answers
99 views
loop inside a loop : search for posts in the same category
Could someone tell me how i could make this work? i have a loop, and i would like to create another loop to find the other posts from the same category : but this does not work :
<?php while ( ...
0
votes
1answer
40 views
How to pull a list of posts in a category while exluding posts in subcategories of the category
I'm using a get_posts() call to pull a list of posts in a specific category. However, the recordset also includes posts in subcategories of the target category.
How can I exclude subcategories from ...
-1
votes
1answer
141 views
Hide gravity forms
I have gravity forms set up on my site and I am wanting to hide/show a form based on whether or not the user has posted an entry into the form/database.
If they have made an entry, then I want to hide ...
0
votes
1answer
485 views
Query only Posts from Both of Two Category?
I have 3 categories,
1.OnGoing projects(cat id='5')
2.Completed Projects(cat id='6')
3.Upcoming Projects(cat id='7')
and also i have another 2 categories:(Not a Sub Category)
chennai (cat ...
0
votes
1answer
950 views
How to query custom post type by term?
This seems trivial but I can't get it to work. Here's my code:
$args = array(
'numberposts' => -1,
'eventcategory' => 'nice-events',
...
0
votes
2answers
173 views
List 'n' number of posts from a Tag, each with a different class or ID
I want to list 'n' number of posts (ordered by latest first) -- post's title linked to the post's permalink -- from a tag on my WordPress blog. I also want to assign each link its own class or ID.
I ...
47
votes
3answers
17k views
When to use WP_query(), query_posts() and pre_get_posts
I read @nacin's You don't know Query yesterday and was sent down a bit of a querying rabbit hole. Before yesterday, I was (wrongly) using query_posts() for all my querying needs. Now I'm a little bit ...
1
vote
1answer
67 views
Sort posts by most recently modified
Is there a way to list posts in the order in which they were modified?
For example;
A user posts 5 posts (#1 being the oldest and #5 being the newest), by default they would be listed with #5 being ...
0
votes
3answers
67 views
Is it possible to retrieve a post and its metadata at the same time?
I usually use two steps to retreive a list of posts and the associated metadata: call get_posts(or a custom WP_Query), and then loop through each post returned and retrieve each posts metadata one by ...
0
votes
1answer
680 views
Adding paging to get_posts()
I'm trying to add paging to the query below. However, I can't seem to get the paging to work. It shows previous/next links, however, they always show the same 2 posts. There are 8 posts in this query.
...
3
votes
1answer
103 views
How to add paging to query
In the script below, I'm calling out from archive.php to functions.php to retrieve a list of posts that have been flagged in a category reserved for my "blog" posts. I'm listing these posts in summary ...
1
vote
2answers
410 views
How to get posts by content?
I found the following codes to get post details.
However, it is not possible to get the posts by content.
Does any one has any ideas?
get_posts()
//// get post ////
$args = array(
'numberposts' ...
1
vote
3answers
607 views
Only get_posts of certain post formats
I'm trying to create a archive list with only my "normal" post format articles (not link, aside, quote, etc formats).
How would I implement has_post_format( 'standard' ), or something similar, into ...
0
votes
1answer
92 views
Using post title as term in query, only working with single word titles
I am using get_the_title to set up the taxonomy term for my query, which has worked fine in testing up until I had a title with more than one word, title of "catalogs" works, title of "new catalogs" ...
2
votes
1answer
108 views
Sanitation needed for WP_Query or get_posts calls?
Just wanted to get a straight answer on this: when submitting query_vars to a call to get_posts or WP_Query, is sanitation needed or does WordPress already take care of that?
1
vote
1answer
526 views
How do I combine these 2 queries
I want to combine the 2 following queries so that ongoing promotions (query 1) shows before the rest of the promotions (query 2) but all together no more than 5 results show. Thanks.
Query #1 Ongoing ...
1
vote
1answer
389 views
get_the_content(“more…”) returns full text
I'm creating shortcode [latest_post] and want to show post date, title and short content. (content has "more" separator). Here is code:
function shortcode_latest_post() {
global $post, $more;
...
0
votes
1answer
498 views
Calling setup_postdata() causes “Call to undefined function get_userdata()” error?
The exact error is:
Call to undefined function get_userdata() in /wp-includes/query.php on line 3567
I am using get_posts() in my plugin, which in turn uses setup_postdata() wherein ...
0
votes
3answers
411 views
Add class to every other posts using get_posts
I am currently using this little loop to display a list of posts using the "events" custom post type
<?php global $post; // required
$args = array('post_type' => 'events');
...
0
votes
4answers
165 views
Why always one post missing
In my custom query, every time I query for posts from a particular category using WP_Query() and the category has 10 posts for example, I seem to be missing a post. So querying for 10 posts only ...
0
votes
1answer
165 views
Both a page loop and posts loop on the same page
I'm trying to get first the content of a single page (the one that is queried), and then in a small section below i want to display the title of my bloggposts as a "Latest News" section.
The problem ...
0
votes
1answer
189 views
Remove posts from query for events whose start date has passed
The query below works as expected, showing cpt event ordered by meta_value, what I haven't figured out yet is how to remove posts for past events or events which have started. The start date for ...
1
vote
1answer
200 views
Exclude images from “inserted into post” when trying to get attachments
I have here the coin-slider which takes all pictures from the gallery. I get the attachments through the following code:
$attachments = get_posts(array('post_type' => 'attachment', 'post_parent' ...
0
votes
1answer
94 views
PHP Syntax Error on get_posts
I have the following coding:
<?php
global $post;
$args = array( 'numberposts' => 8);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : ...
0
votes
1answer
459 views
Single random post in homepage
I want to display single random post in it's entirety in the homepage.I've tried many methods, but the main issue was that it won't display the content, only heading, or display content, but only an ...
1
vote
1answer
244 views
My post repeats itself on the second page [closed]
Hey the way i have my index coded is that it shows one full post and the rest of the post are excerpts, but when i click previous the 2nd page shows the same post from the first page, what can i do to ...
0
votes
1answer
54 views
How do I query posts and have their related taxonomies returned in the results?
I have created a custom post type that contains television channel data. Each channel has its own post. I have also created a custom taxonomy of channel groups. What I want to do is query all the data ...
0
votes
1answer
58 views
get_posts seems to be skipping the last Post
I have custom post type (Events) with 6 events.
$posts = get_posts( array('post_type' => 'events') );
echo '<!-- ';
print_r($posts);
echo ' -->';
This code shows the 5 with the most recent ...
0
votes
1answer
321 views
0
votes
1answer
380 views
Getting the list of the latests posts and custom type posts in the homepage
When I need to get a single post type list I usually use get_posts, how can I retrieve multiple custom posts types to populate the site homepage?
To be more precise, I would like to get the latest ...
0
votes
1answer
236 views
Exclude post format from get_posts
The title basically says it all.
I know I can use the following to get posts from the aside post format:
$args = array(
'post_type'=> 'post',
'post_status' => 'publish',
'order' ...
1
vote
1answer
3k views
How to show related posts by category
In my gallery site i want to show other pictures under the current picture (in single post). I seen more codes but it i asks to specify the category, but i dont want want specify the category manually ...
