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
30 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
23 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
38 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
64 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 ){ ...
1
vote
0answers
70 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
64 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
81 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 query_posts('post_type=post&...
2
votes
2answers
149 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
103 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
34 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
25 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 Taxonomies....
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
329 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
58 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
205 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
55 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
67 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
59 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
168 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
184 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
261 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
149 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 me....
0
votes
1answer
165 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
44 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
33 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
185 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
24 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 feat-...
0
votes
2answers
118 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
228 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
31 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
87 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
34 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
130 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
45 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 ...
0
votes
0answers
33 views

How to search posts by title, id and author? [duplicate]

i am getting the details from a custom search with the below query from a parameter $_REQUEST['search'] in the URL $custom_args = array( 'post_type' => 'post', 'posts_per_page' => 5, ...
0
votes
1answer
26 views

get_posts array 'between' not behaving

if I make the query of $apartments = get_posts( array ( 'post_type' => 'apartment','meta_key' => 'bedrooms','meta_value'=> array(4,12) , 'compare' => 'BETWEEN' , 'type' => '...
1
vote
0answers
67 views

Pagination with an array of post objects?

I am curious, I have the following code: foreach ($this->networkBlogs as $siteBlog) { switch_to_blog($siteBlog['blog_id']); foreach (get_posts() as $postObject) { ...
0
votes
2answers
77 views

This wp_query will not return any posts and only seems to work with post_status inherit?

I'm having difficulty returning a list of posts. This file is contained in a plugin folder (ultimately I want to have a cron job just run the script here to delete posts with invalid urls in the given ...
0
votes
1answer
74 views

Even with PHP plugin get_posts not working in widget area

I have the following code in a template, it and displays images form a custom field: <ul class="about-us-grid"> <li> <?php $posts = get_posts('post_type=employee&orderby=rand&...
0
votes
0answers
63 views

Group by multiple taxonomies and hide empty loops

This was helpful for grouping, but didn't quite solve another issue I'm dealing with: Display category posts grouped by taxonomy I've got two different variables to sort through. 'product_type' and '...
0
votes
0answers
46 views

Querying on a custom post type without tags returns no posts

A theme I'm working on contains a custom post type, "help_question", which is declared as such in functions.php add_action( 'init', 'create_post_type' ); function create_post_type() { ...
1
vote
0answers
48 views

Query if audio attachment AND/OR custom field

I've been trying several things but to no avail... Searched, maybe not good enough though! I have posts that either have an uploaded audio file AND/OR has a Soundcloud link (which is a custom field). ...
0
votes
0answers
38 views

URL rewriting taxonomy term

I'm trying to find solution for the following hours now and i don't know if this is applicable. I have 1 Custom Taxonomy "Years" for Post Type "Post (default)". The taxonomy has 2 Terms: "2014" and "...
0
votes
0answers
163 views

Pre_get_posts meta query value serialized array using multiple URL parameters

Using the 'pre_get_posts' action I'm looking to return all posts which match multiple URL parameters by defining the meta_query. For example: example.com/?size=large,small&options=green,blue,red ...
0
votes
2answers
59 views

How to Retrieve Post ID of another page

I have a post and payment page each posts contain a payment form I want to know how I can retrieve the data to I can execute and publish where the post payment came from on payment form submit $...
0
votes
1answer
123 views

How to get the intersection of two terms both from different custom taxonomies

I have a custom post type listing Then there are two custom taxonomies job_listing_region job_listing_category On home page i have links to job_listing_category like shop,eat,stay etc. and job ...
0
votes
1answer
52 views

Get posts in between specific ID's

I want to get the posts from within specific ID's ( 10 - 15 ), just like we do in SQL select * from employees limit 10 , 20 ; I wanna get in this Wordpress posts.
0
votes
0answers
41 views

Weekly most viewed posts

My code returns most viewed posts. How can I show weekly most viewed posts? Here is my code: $args = get_posts( array( 'meta_key' => 'post_views_count', 'orderby' => '...
1
vote
2answers
155 views

Display latest x posts from all categories in Custom Post Type/Taxonomy

I am attempting to display the latest x posts from all categories using a custom taxonomy called 'case-studies' in WordPress. I have managed to output all the category names as heading links I have ...
1
vote
1answer
116 views

Get posts from specific taxonomy term

I have nhl news website and I have taxonomy for each season (ex 2014-15) Taxonomy in functions: function wptp_register_taxonomy() { register_taxonomy( 'season', 'post', array( ...