get_posts() is a function for creating multiple loops. It retrieves a list of latest posts or posts matching criteria.

learn more… | top users | synonyms

2
votes
2answers
705 views

get_posts meta_value is serialized array, how can I grab specific posts with combination of meta_key/meta_value[0]->is_featured?

I've a postmeta key saved in DB: mediSHOP_product_extras It's value is Unserialized: Array ( [0] => Array ( [is_slider] => 0 [is_featured] => 0 [in_stock] => 0 [video_url] => ...
1
vote
1answer
21 views

Only showing the_date and the_excerpt for first entry in get_posts

this code below shows the titles and links for 5 posts in get_posts no problem but only displays the date and excerpt for first post... any help please? <?php $args = array( 'posts_per_page' ...
209
votes
6answers
71k views

When should you use WP_Query vs query_posts() vs get_posts()?

It seems like half the tutorials in the Codex and around the blogosphere use query_posts() and half use WP_Query. What's the deal?
0
votes
2answers
30 views

Fetching All Posts (200+) in a Category - Performance Issues?

I want to get the IDs of the 2 previous and 2 next articles in a certain category to show them as a "related videos" playlist. I know that there are the functions previous_post_link and ...
0
votes
3answers
75 views

Paginate get related post by author function

Is it possible to get this function paged? I've tried to add previous and next links but i'ts not working... function get_related_author_posts() { global $authordata, $post; ...
3
votes
1answer
8k views

get_posts - get all posts by author id

I want to get all posts by certain author id (current user). Later, I want to pick the first post made by this user (ASC). I guess I do not use the right arguments in get_posts, am I? ...
1
vote
1answer
4k views

Sort “get_pages” by menu order not ordering

I'm using this bit of code to generate a page full of items but they won't sort into the menu order, any ideas as to why? <?php $pages = get_pages(array('child_of', 'menu_order')); ?>
1
vote
1answer
302 views

Getting movie and serial on actor page

I'm building a cinema site, I came with a problem, let me explain: Movies- are stored in Post's Actors- are stored in Post Type - persoane ( taxonomy= lista) Serials - are stored in Post Type - ...
0
votes
2answers
2k views

Custom Taxonomy with tax_query

So I've created a custom taxonomy type with a plugin (CMS Press) and now I'm trying to get all of the posts with the taxonomy terms in that taxonomy. My get_posts looks like this: $args = Array( ...
0
votes
0answers
8 views

Display Children Category post and child post under it

Hi I need to display only child category post in home page and then its children title under it in home page recent posts . While doing this it displaying category children post too in home page ...
0
votes
1answer
2k views

Sort get_children by menu_order

I'm using the jQuery Carousel Gallery and unfortunately it's not working with WP's new v3.5 gallery ordering. When the client drags to rearrange images, those changes are not reflected in the ...
0
votes
2answers
55 views

Get posts by category name

I'm having a terrible time trying to figure this out. I've registered a custom taxonomy (clinical-programs) and like to list all the PAGES that are assigned to particular page(s).
4
votes
3answers
568 views

List most recent image uploads, but only for specific custom post type

I can get a list of the most recent image attachments like so: $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => $number, 'post_mime_type' => ...
1
vote
1answer
361 views

AJAX pagination offset returns same post on adjacent pages

I have a simple AJAX pagination that seemed to work just fine, calling one Wordpress page (not ideal, I know) with a pagenum and a sort order arguments and it returned 4 custom posts per call. The ...
0
votes
3answers
978 views

Get id of category from drop down menu

Im trying to get the category ID from wp_dropdown_categories();and then pass the ID into a loop to have it output posts titles from that particular category. I currently have this: <form ...
0
votes
2answers
2k views

Pagination with get_posts seems to work but links not showing

I've a custom page template where I want to query 2 posts from a post type and 1 post from another post type. I have it set up like this: $paged = get_query_var('paged') ? get_query_var('paged') : 1; ...
0
votes
2answers
34 views

Display all Post titles with Category and Tag

I am trying to display all posts that are in a specific category and have a specific tag. This is what I have so far but it seems to ignore the & and make it or. <?php $myposts = get_posts( ...
0
votes
1answer
25 views

Get x recent posts by author?

So I have ten authors on my site, and I want to designate a section where it shows the ten authors and their 5 latest posts in the form of the post title linking to the post. I tried using the ...
5
votes
3answers
1k views

Regenerate Slugs From Title of Posts

is it possible to regenerate the slugs programmatically after changing the titles of the post? Numerous post titles were updated and the slug was not updated with the title so I need to regenerate all ...
3
votes
3answers
11k views

get_posts assigned to a specific custom taxonomy term, and not the term's children

Say I have the following taxonomy terms: Term 1 Term 1.1 Term 1.2 Term 2 Term 2.1 How can I get only posts that are assigned to Term 1 and not include those that are assigned to Term 1.1 or ...
0
votes
0answers
14 views

Send POST variable with 'post_publish'

I have a custom button which triggers my page builder to load on the post.php page upon clicking it. However, I want to send a variable as well with it. Here's what I tried $('#post').attr('action', ...
0
votes
1answer
31 views

Get all posts with a certain meta key, except for one with specific title

I need to return all posts with post_test_safe == 1 and exclude one with title ="Special title" Some kind of combined meta query but haven't got anything to work. function getAllPostIdsTest(){ ...
0
votes
1answer
25 views

Worpress url parse

I want to display posts in certain category only with given tag. Problem with parsing url slugs. For example, I have category named 'Clothes': example.com/clothes/ I can get posts in this category ...
1
vote
3answers
72 views

WP Query post meta value

I'm trying to get posts which have applied the meta value trainees. $args = array( 'posts_per_page' => -1, 'orderby' => 'post_date', 'order' => 'DESC', ...
0
votes
1answer
87 views

SELECT * FROM $wpdb->posts WHERE ID > 160

I would like to retrieve all posts and relative tag with ID greater than 160. I tried: '$args=array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 5, 'orderby'=> ...
0
votes
2answers
7k views

How to display posts by current user/author in a custom page template?

I am a trying to create a dashboard like custom page template that list post of of the current logged in user. I've tried to find a solution on the net. but none were appropriate
1
vote
1answer
52 views

WP_Query post_parent parameter always returns children of current page

Well the title gives it all away... Here's the code: $args = array( "post_type" => "page", "post_parent" => $cat, // runs through a loop of 5, 128, 130 "posts_per_page" => -1 ); ...
0
votes
3answers
48 views

Re-sort get_posts query results

I have a query that pulls fields from the 3 most recent posts for a carousel: get_posts('posts_per_page=3') I need to re-order the results so that instead of it being 1, 2, 3 it is 3, ...
1
vote
1answer
465 views

get_posts() not working in functions.php

If I use the following function in any theme template, it works as expected. However when trying to use it within an AJAX function in my functions.php, it returns empty. $args = array ( ...
0
votes
3answers
584 views

Get only used meta_values

this is how I'm getting the meta values: $apart_locations = $wpdb->get_col( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = 'postal_location' ORDER BY meta_value ASC" ); This is how ...
0
votes
1answer
41 views

XMLRPC - getPosts - How to call from remote site?

For the purpose of this question, I have two WordPress websites. Let's call them "Portfolio" and "News". Portfolio is a "pages" only website while "News" is a "posts" only website. On the Portfolio ...
2
votes
2answers
2k views

Get posts by meta data OR title

I have a working query that calls all my posts that have a certain meta value for one of two meta keys: $term = $_GET['term']; $args = array( 'post_type' => 'some_cpt_name', 'meta_query' ...
0
votes
2answers
60 views

get_posts query matches too many results

I have a query inside a function that is returning matches that i don't want, for example when the $id=116 it is also returning results where the meta_key 'funds_id' is 11687. public function ...
-1
votes
2answers
45 views

Latest post on specific category and custom css

I'm trying to create a new home page with two columns for latest post of specific category. This the page code: <div id="left-column"> <div class="bloccorosso">News & ...
1
vote
1answer
27 views

Inserting custom data to the_post() during loop

I have some posts on my WordPress site, and let's say I want to add a random number for each post with $num as key and random() as value. Then I want to access them with something like: $post->num ...
1
vote
2answers
45 views

Get posts under custom taxonomy

I am not getting the posts under custom taxonomy(fabric_building_types).I am getting cat_id and cat->name also but not able to get the posts. $args = array( 'type' => ...
0
votes
0answers
20 views

Posts of Certain Category as Menu

I want to retrieve posts by certain category dynamically as a menu. What I need is: On the left-side of the page I want to display a menu as following | Category Name | | Post of This | | ...
0
votes
2answers
56 views

Reworking function for counting custom post type posts count

I am trying to rebuild my inline posts counting to a function. What would be the best way to do that? Here is my inline code: $posts = ...
1
vote
1answer
60 views

List all posts from past week grouped by sub-category

On a category specific template, I want to list all the posts from the last 7 seven days for that single single category and group them by subcategory. This is the code I have so far, which lists the ...
0
votes
1answer
35 views

Cache Get_posts

I have a query (see below) that gives a list of 10 news items ordered by the meta value "event_date" and filtered so that only posts earlier than today are displayed. This query is taking two seconds ...
0
votes
4answers
242 views

How to limit get_posts()?

I've been researching this for the last 3 days. I'm triyng to limit the maximum amount of posts retrieved by get_posts(). I have this chunk of code: // all filters should be applied here $args = ...
0
votes
1answer
42 views

get_posts() using an array of post ids [closed]

There's an array of post ids, and I'd like to use it to load these particular posts. I'm using get_posts() but there's some kind of problem using an array for 'post__in' argument. Here are the ...
6
votes
3answers
36k views

Query for custom post type? [closed]

I have installed the Custom Post Type UI plugin. After activation of this plugin I have created a custom post type called portfolio. Now I want to use this on the portfolio page in the front-end. How ...
0
votes
2answers
55 views

Get all pages and posts with get_pages() or get_posts()

Trying to get all posts (with all I mean all pages, posts and posts from custom post types). Is this possible? The documentation says I can only pass a string as post_type so how can I get all pages ...
0
votes
0answers
45 views

wp_list_pages show all pages in sitemap

I am trying to list the pages of my site but actually list them all. I can use wp_list_pages(); However I have a custom post type "services" with archive false. I also have a page named services ...
0
votes
0answers
104 views

How to implement AJAX pagination for get_posts (CPT)?

I need to implement AJAX pagination: « Previous 1 2 3 ... 70 Last » for a CPT get_posts() loop: // main images query // all filters should be applied here $args = array( ...
0
votes
1answer
125 views

Display content based on a users login

I was wondering if this is possible. I created a client portal where they can see all of their work that was assigned to them (this is all being displayed on the frontend). Once they login, they are ...
0
votes
0answers
28 views

Get Posts by tag from a custom taxonomy

I have a custom post type called product, which have two custom taxonomies named as product_tags & product_categories. In My Product Categories archive page, I am listing tags. My requirement ...
0
votes
1answer
73 views

Why the_excerpt() function returns excerpt on the Home page and trimmed content in sidebar?

I have this code to display 4 posts of type "testimonial" on the Home page: <?php $custom_posts = get_posts([ 'numberposts' => 4, 'post_type' => ...
0
votes
1answer
134 views

attachment.php & flexslider—linking thumbnail to specific image

I am nearly there but need the help of the community to bring me home! I am linking from a "gallery overview" page (thumbnail grid) to a single, full-size image page (attachment.php) containing a ...