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
1answer
8 views

Find owner of coupon

I'm attempting to run a function for a user if they have a certain coupon. I'm using the plugin Smart Coupons to generate coupons with prefixes and suffixes. I can get a list of all the coupons in ...
-2
votes
0answers
15 views

Display posts on page template where category matches the page's custom field

I'm attempting to create a page template that displays posts that have a category that matches that page's custom field values. In the page template I have a custom field named "Page Category". If ...
0
votes
1answer
46 views

Meta Query with date and time on the same Day before given time

I have a metaquery for a custom post type "events". Their start date is stored as a meta field in this format: 2016-02-05 19:00:00 These are my query args: $args = array( "posts_per_page" ...
0
votes
1answer
23 views

Get Post content in another file?

I am working on a plugin .I have a custom post type team.Custom post has four posts of different categories.I used this code to send post id of each using ajax. $(document).ready(function () { ...
1
vote
1answer
19 views

Meta Query returns wrong number of posts

I am using this meta query inside a category: $args = array( "posts_per_page" => 12, "post_type" => array( "event", "post" ), "post_status" => "publish", ...
0
votes
1answer
21 views

Query get_posts by level depth

I have a page structure like this: -- Asia ---- China ------ Shang Hai ---- Hong Kong -- Africa -- America ---- USA ---- Canada I want to use get_posts to get all posts that I marked in bold ...
0
votes
0answers
19 views

get_posts ( $args) failing when called by AJAX

Here's my code: function ajax_test(){ $default_workout_category = 61 //Hardcoded category for testing $args = array( 'category' => $default_workout_category, 'orderby' => 'title', ...
1
vote
1answer
22 views

Get posts by name and taxonomy term

How do I get all posts that has a taxonomy term and a specific name/slug? I have tried with the following arguments but without getting the wanted result. What am I missing, how can I combine the ...
0
votes
0answers
14 views

Decrement term in for each

So I am catching custom posts in wordpress by for eaching my custom terms. To get a post from the next term in the loop I use $terms[++$key]->name and it all works fine. However when I want to do the ...
0
votes
0answers
15 views

Get Custom Post Type posts on normal edit-posts and pass to TinyMCE

I am following a tutorial for adding a dropdown list in tinyMCE editor. In the end I would like to have a Select list similar like it is in this image , but populated by post titles from Custom Post ...
7
votes
1answer
101 views

Alternative to get_posts() due to multithreading cache crash

I am using pthreads to creat multiple threads. Each of those threads at one point tries to use get_posts() as follows: $args = array( 'post_type' => 'post', 'post_status' => 'any' ); ...
1
vote
1answer
24 views

WordPress takes too long to show 404 error on images (on LEMP stack)

I have installed WordPress on LEMP stack on DigitalOcean and noticed that all the 404 images on the pages are taking too long to show a 404 error message. Those images are not existing so it will ...
0
votes
0answers
24 views

Getting posts for a category

I have a menu made up of categories, click a category shows the users list of articles beloging to said category. However I seem to have stumbled across a problem if a post belongs to 2 or more ...
0
votes
1answer
30 views

offset and max_num_pages in pagination gallery

I rewrote the code galleries and stopped at the pagination. How can I get the maximum number of pages? at the moment I can not define it, and put a test for the number 5. (Here "for ($ i = 1; $ i ...
0
votes
3answers
35 views

How can I use wordpress functionality outside of WP framework

I require to retrieve a list of the recently created blog posts or any Query-based usage of WP posts inside my PHP website and not within WP framework. I am new to Wordpress and stucked here. I ...
0
votes
2answers
34 views

Custom Post type Query post is not working

I created a custom post type tickets, than I added few tickets in it. But with the following code, I tried to show list of tickets submitted by the current user and its not working for me. global ...
0
votes
1answer
28 views

Any difference betweenn posts and pages for one page?

Ive been checking out wordpress but Im having some trouble figuring out what I should use to get the text from wp on my site. Posts or pages. Im making a one page website. I know how to get text from ...
-1
votes
1answer
21 views

Intergrate WP into website

I am trying to integrate WordPress into my website. I can pull all the information, except the image. I use the code below: require( 'my-blog/wp-blog-header.php' ); $posts = get_posts( ...
0
votes
1answer
22 views

Creating a custom search for a specific post type

Ok, so we know Wordpress comes with a built in search form. However, I've created a custom archive page that lists posts from a specific post type. I would like to integrate a search box that only ...
0
votes
1answer
33 views

Display Recent Posts in BuddyPress Profile

This is the code I use to get recent WordPress posts. <h2>Recent Posts</h2> <ul> <?php $recent_posts = wp_get_recent_posts(); foreach( $recent_posts as $recent ){ ...
0
votes
0answers
34 views

'exclude' argument is not working with get_posts for a custom post type

I'm trying to use get_posts to get a random list of customPostTypes but I want to exclude some id's. I already try the query with the following options: Current) 'exclude' => array(622, 621) --- ...
0
votes
2answers
43 views

meta_query: check if number exist

I'm using the following query to check if user id exist in a custom meta field: 'meta_query' => array( array( 'key' => 'participantes', 'value' => $user_id, ...
-1
votes
2answers
47 views

query_posts works while get_posts doesn't

I try to create a page that shows my posts (a page different than the "posts page" defined in wp-admin). When I copy my index.php into this new page and add <?php ...
2
votes
2answers
136 views

Display 4 chronological posts starting with a random post

I know that I can display 4 random posts by doing something like: get_posts('orderby=rand&numberposts=4');   What I'm trying to achieve is starting with a random item, but then showing ...
0
votes
1answer
47 views

Help ordering custom query by Title, Ascending

I have an old project (custom post type query) that needs an alteration and my memory/skill level is lacking for what to do. With the code below, I'm needing to return the first query in alphabetical ...
0
votes
0answers
27 views

user_has_cap filter crashes site when doing get_posts()

I can not understand why the site is crashing when adding this block of code: function demo_function( $capabilities ) { global $pagenow; if ( $pagenow != 'post-new.php' ) { ...
0
votes
1answer
22 views

How to get posts by category and by choosing a taxonomy term?

I'm new to Wordpress and I've managed to build most of a full custom theme for wordpress on my own. But the tricky stuff is starting to show its tail, and I've spent the last days stuck on ...
1
vote
0answers
20 views

Query to only return the 2 newest post attachments (images)?

How can you make a query that runs through all posts in a category and outputs only the 2 newest image attachments (most posts in the category have no attachments)? My current query is like this: ...
0
votes
1answer
111 views

How to use get_posts() function in functions.php

I am trying to load posts with ajax. But I am not getting any content of the posts. I am not posting my javascript since it is pretty straight. Here is my code in inc/helper-functions.php which is ...
0
votes
0answers
27 views

Ordering Posts by parent category, name ascending

I am currently creating a theme, and I have 2 parent categories: Budget and Brand. On home.php, I want to order all the posts ascending by their sub category name without showing the category title. ...
0
votes
0answers
75 views

Display custom post type AND posts from a certain category

As the topic says I want to show posts from one category (band-news) and posts from a custom post type (artist) in the same loop. I got this but as you can see it want do as I wish: <?php $posts ...
0
votes
0answers
26 views

Search on Category and BETWEEN custom meta field

Background I am building simple car theme where I want to review cars, however, I'm really struggling with my search implementation. I have added a couple of custom meta fields to the post including ...
0
votes
1answer
65 views

Loop through two different sets of custom fields

I created a Custom Field ('custom_name') to allow content editors to specify a 'custom_name' (different from the title of the page) to any post created: custom_name - (Field type --> 'text') For a ...
0
votes
1answer
58 views

Loop through incrementing custom fields

I created 4 custom fields for a specific page. Field type: Post Object (I grab thumbnails and titles from the posts) Field names: featured_content_1 featured_content_2 featured_content_3 ...
0
votes
0answers
64 views

Posts not showing when category is clicked

I have a site: microman.be. The blog was imported by Blogger Import tool. All posts are visible, on the blog page too. When I click on a category in the blog sidebar an empty page turns up. The URL ...
0
votes
0answers
121 views

How to get post content by get_posts function?

I'm newbie at Wordpress and now I need to get the post content in events plugin. I have simple array: $event = get_posts(array( 'name' => $events_array[$i], 'post_type' => ...
2
votes
2answers
174 views

How to show next Post Thumbnail image in WordPress using current post id

i make a wordpress theme i make a grid structure show below i have this grid structure it contain two rows and every row has three column i want to show my wordpress random posts in this grid ...
2
votes
3answers
113 views

Order posts according to user defined order for meta values?

I have set up some CPTs and storing a meta key/val for each of them. When I get those posts, I need to order them by the meta value, but, the order of the meta values will be defined in an array by ...
0
votes
1answer
94 views

Use not custom fields in get_posts() meta_query?

Is it possible to use not custom fields in get_posts()'s 'meta_query' to use a or-relation statement with a custom field and a category id? Like this: $args = array( 'posts_per_page' => 6 ...
0
votes
0answers
34 views

How to Create Random post once in a day

Hello Guys I am having issue with the code i found here I wanted to add specific custom post type to be randomized once in a day and i used the code i found here but that repeating the content on ...
0
votes
1answer
23 views

get_posts $args won't accept array as one of the criteria?

The goal is to list attachments underneath a WooCommerce product, using the tags from that product. Everything works fine if I manually enter the tags at 'product_tag', but when I try to use an array ...
0
votes
0answers
77 views

$wpdb->query(update) not working as supposed when passing GET request in the where clause

I have made a table 'wp_mostfavourite' in wordpress database, it has got three fields, 'serialno', 'postid', 'counts'. The 'counts' is supposed to be increased by 1, whenever the following query is ...
0
votes
1answer
20 views

Unable to render custom field after attempt to generate a list of recent post in page template

When I try to render a list of recent post type either by using WP functions or WP query, I'm not able to render the custom fields that I have to render bit after. The content of box with class ...
0
votes
2answers
93 views

Sort posts according to date

I have problem with sort posts according to date: My code now: <?php global $switched; $original_blog_id = get_current_blog_id(); // get current blog $blog_ids = array(4,1); foreach( $blog_ids ...
5
votes
2answers
187 views

Delete all posts from WordPress except latest X posts

On a project I require to keep only 10 latest posts on website and auto delete all other posts. So I came up with this function which triggers on post publish/update and I used offset parameter to ...
0
votes
0answers
21 views

Secondary ordering and order DESC not working when using meta_value_num

I have this query: $args_members = array( 'posts_per_page' => -1, 'post_type' => 'team_member', 'post_status' => 'publish', 'meta_key' => ...
0
votes
1answer
44 views

Loading post template that contains a nested loop with ajax

I'm currently working on a project where I'm loading a post with ajax. I'm using get_post() to get the post, setup_postdata() to setup the post data, and get_template_part() to load the template ...
0
votes
3answers
32 views

Order post by taxonomy

I am trying to write a get_posts() query to retrieve 7 posts per page. The retrieval of these posts are based on 3 different tags, "Featured","Highlighted", and "News". Now the "Featured" post take ...
0
votes
1answer
70 views

Why does get_posts only show results for Admins or logged-out users?

I use a get_posts() call with these arguments: array(6) { ["include"]=> string(14) "1633,1634,1635" ["post_status"]=> string(3) "any" ["post_type"]=> string(10) "attachment" ...
0
votes
1answer
38 views

numberposts not responding to wp_reset_postdata()

I am working on a loop where I want the content (from 2 separate categories) to be displayed like this: 1 large format post, 1 random product, 2 small format posts, 1 feature post ...repeat. In order ...