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

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; ...
4
votes
3answers
538 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
487 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] => ...
0
votes
1answer
28 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
20 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 ...
0
votes
1answer
1k 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
1answer
1k 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 ...
1
vote
2answers
635 views

WordPress get posts by date without query_posts

I'm want to get posts from the last 30days in a sidebar but I don't want to use query_posts, is there a way to achieve this with the get posts function?
1
vote
1answer
270 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
1answer
312 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
1answer
325 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
590 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
1answer
90 views

List latest posts with least comments in WP-Admin

I want to encourage my authors to provide feedback to new posts that have not received enough exposure. To do this, I want to add a box to WP-Admin that lists the top 3 latest posts (from the past two ...
0
votes
0answers
44 views

Custom query not working in plugin admin page

I'm not sure what I am doing wrong, but I cannot use get_post, get_posts or WP_Query in my plugin admin page. I can use get_user_meta, and get_userdata, so I'm a bit confused as to why I cannot use ...
1
vote
3answers
53 views

Can I set and show “important” post in my blog?

I have the following doubt related to the WordPress posts showed in the home page. I know that in the home page I can show the latest published posts. But can I also show (before the latest posts) a ...
1
vote
2answers
2k views

how to get specific page content

bellow is my code working nice but problem is don't coming with html tag.. like etc... no idea why... <?php $recent = new WP_Query("page_id=2"); while($recent->have_posts()) : ...
0
votes
1answer
26 views

one get_posts to return a number of custom posts for each meta value

I have setup a custom post 'product' with a custom field cf_type. I wish to have one get_posts that will return 20 total products, 10 products with cf_type: fog and 10 with cf_type: gof. Is that ...
0
votes
2answers
26 views

How to get latest page (not post) of User and display the content

I've been trying to get the latest Page, not post, by author ID and display it on a page. The reason it has to be a page and not a post is that the user will only be posting one page and a whole ...
0
votes
1answer
6k 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
0
votes
1answer
39 views

How to create content automatically when a post is published?

Goal: Ability to automatically create content in WordPress posts/pages. Goal Details: When a post is created/published, it will automatically create or configure content based on the base data inputs ...
0
votes
1answer
1k views

Display post details by post ID

I need to display post details by ID on front page template (front-page.php). On the front page I want to display the post’s title, excerpt & featured image. I have tried to do that but no idea ...
3
votes
1answer
1k 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, ...
0
votes
0answers
38 views

How to use get_categories results called in header.php on the homepage as well without calling the database twice?

I have a Wordpress blog with multiple categories and I have to display the last two posts of certain categories(not all of them) in the header. This is so as to have this information available ...
0
votes
2answers
32 views

Sort order in get_posts [closed]

I've created a custom template for a client. This is going to be a multilingual site setup on a Multisite install. As you can see under each category letter, the posts start out in alphabetical order ...
-1
votes
1answer
39 views

Display post's description and caption

I am trying to get and display 5 featured posts. To achieve this target I have an offset of 5 recent posts. I have successfully fetched the posts' id's and images, but I failed to get every post's ...
0
votes
1answer
25 views

Help to cleanup this code

I am trying to change my attachment page link yo example.com/photos/attachment_ID/post_name/attachment_name can you tell me how to call the parent post name function wpd_attachment_link( ...
0
votes
0answers
18 views

how to get wordpress categories list with thumbnails?

i am trying to get thumbnails list with their thumbnails images .i tried code below but it only gives categories list . i know there a could do using feed_image but i can't figure out how to do it ...
0
votes
1answer
92 views

Change attachment inside the_content using filters

I am in search of a snippet or function that will filter the embedded images inside a post to a custom size I have defined in functions.php. Here is the scenario: A client uploads and add any ...
0
votes
1answer
22 views

get_posts() forcing ignore sticky posts on main loop

I have a custom query using get_posts() that besides ignoring sticky on its main query, ignores sticky posts on main loop. Reading around I've found that get_posts() have some trouble with sticky but ...
0
votes
1answer
26 views

Exclude parent category when getting category posts by slug

I have the following category layout: Resources -- Documents I want to list the posts in the documents category, and have the following code: $args = array( 'posts_per_page' => ...
0
votes
1answer
24 views

what is the maximum number of post a wordpress loop can work with?

what is the maximum number of post a wordpress loop can work with? how many post can i display with 'posts_per_page' => -1? ive got 50,000+ pages and I want to sort through them, but I just get ...
0
votes
1answer
23 views

the paged param is allways 0

I am listing a custom post_type called ad using get_posts wich works fine, Problem that I have is that I am not able to read the paged param, wich I need in order to enable pagination, The thing is ...
0
votes
0answers
31 views

A Depth Like Parameter For “get_posts”

Wordpress has stumped me for the first time in a very long time. I am trying to limit the depth of a get_posts call in my template. I want to get children but limit it to a depth of only 3 as I am ...
0
votes
2answers
50 views

show posts in different styling

I would like to show categories in the front page with different behavior: categories to show posts in two styles [Three posts having the same style and then another two with the same style] ...
3
votes
2answers
220 views

How do you get posts by meta_query using the JSON API plugin?

I would like to get post with an API method using a kind of meta query. I have 2 custom fields "place" and "dayoweek" and I want to retrieve via API call all the post that have some values for this 2 ...
0
votes
1answer
35 views

get_post_meta slowing down my page load (in a plugin)

I've been working on this project where I need to load events (custom post type) and a whole bunch of meta data for every event. The problem is that page loading times are getting longer and longer ...
0
votes
1answer
55 views

Secondary Query Is Breaking Main Query

I registered a Custom Post type called "quote" and I am trying to show a single random quote on every page of my Wordpress site. I'm pulling out a single quote with the following code: $args = ...
0
votes
0answers
26 views

Any way for get_next_post() to use the actual post order instead of publish order?

I'm currently using get_next_post() and get_previous_post() to get their ID so that I can permalink my next/previous buttons for a custom post type. I'm also using a wordpress plugin called "Anything ...
1
vote
1answer
43 views

Get posts from taxonomy URL

How can I get the posts from a custom taxonomy using the URL to determine which taxonomy term id is being shown? I tried to get posts via a category using get_category_by_path which returned false ...
-1
votes
1answer
41 views

show custom post's post in two different divs [duplicate]

I have created a custom post type. For that I have used this code add_action( 'init', 'broker_post_type' ); function broker_post_type() { register_post_type( 'new_broker', array( 'labels' ...
0
votes
0answers
27 views

Issue with recent custom post type permalink

I'm using the following code in my footer to get the latest posts from specific custom post type. <?php //WordPress loop for custom post type with taxonomy $my_query = new ...
0
votes
1answer
32 views

Wordpress plugin: Getting posts where checkbox selected

I would like to have a plugin where I could work with all post data from posts that have a selected checkbox.. To get all posts is simple with the get_posts( $args ); function... But how to add a ...
0
votes
2answers
68 views

Retrieving 3 latest post from each of 5 different custom post types

I have 5 different custom post types. I am showing 15 latest post from them on my home page using following query: $query = new WP_Query( array ( 'posts_per_page' => 15, ...
0
votes
2answers
117 views

Auto-change Post Status on First Page Load

I have created a number of custom post statuses using the EdiFlow plugin. Now, what I am trying to do is, if the contribter visits the post edit page and the post status is "assigned" to automatically ...
0
votes
1answer
55 views

Custom loop in addition to default on archive page

I'm trying to create an interface on the admin that will allow our authors to select top resources to place as an aside on our archive page. I'm trying to add a loop in addition to the original query ...
0
votes
1answer
82 views

get_posts works but new wp_query doesn't

I was told that get_posts is a very bad function to use that that making a new WP_query is absolutely better. My problem is that my get_posts code works but when I tried turning it into a WP_query, ...
0
votes
0answers
79 views

404 Error is showing when open page posts

I just downloaded the video theme from templatic, when i am displaying videos from the thumbnail, it shows 404 error Link to the page It is not showing the video, how to avoid this problem and show ...
0
votes
1answer
37 views

get_posts not honoring post_status

I have a custom post type 'license' with custom post statuses 'active,inactive,cancel,expire'. However when I run a get_posts query to get only posts with active status it returns all the posts ...
0
votes
0answers
306 views

Show all posts using the template page and the loop?

I am trying to make a template page that would display all posts from all categories, in short - every post added to my website. I was googling around and found out that it can be done by using The ...
1
vote
1answer
87 views

What's wrong with my date_query?

It's WordPress 3.9 "Smith". I'm trying to implement a new Archive page as per the suggestion of @Milo. $categories = get_categories( $cat_args ); //it's NOT important for the Q, as it's fetching ...