Articles of wp query

2 orderby in wp_query with 2 custom fields

I’m triyng to display hotels (taxonomy which i have created) by two ‘orderby’ with wp_query but i’m not success. Results looks likes: Hotel 1 : 2 persons 5 stars Hotel 2 : 2 persons 4 stars Hotel 3 : 2 persons 3 stars Hotel 4 : 3 persons 5 stars Hotel 5 : 5 persons […]

List all custom post type posts from a given category?

I have a custom post type myposttype and it’s taxonomy is called myposttype_categories. myposttype_categories have multiple terms inside, such as foo and bar. The tricky question is – how do I list all myposttype posts that belong to foo (or bar)? I thought this should work, but it does not: $args = array( ‘post_type’ => […]

2 loops on page – one with orderby rand second orderby date

What I’m trying to achive, is to set 2 loops on one page. First one takes 11 latest posts and sort them in rand order. Second show the rest of posts ordered by date. FIRST LOOP $args = array(‘posts_per_page’ => 11,’orderby’ => ‘rand’ , ‘order’ => ‘ASC’); $loop = new WP_Query($args); $do_not_duplicate[] = $post->ID; while […]

wp_query orderby title and meta key value (WP3.1)

I have a taxonomy wp_query and i would like to order the list by title and by meta value (numeric value) Have a meta value Interesting = 1 or 0 in the posts Not so interesting posts would be at the bottom of the query GOAL – OUTPUT LIKE THIS: (is this possible with WP_QUERY […]

WP_Query orderby post__in remains ineffective in the Loop

I’m trying to query a custom array of posts for the homepage, trying to maintain the order given in the array. To a certain degree this works fine, WordPress finds the posts, but in the Loop the order is all mixed up again. First of all, I’m using the pre_get_posts hook to change the main […]

How to get most recent commented post above new submitted post in WordPress?

I have this function: $ids = $wpdb->get_col(“SELECT DISTINCT comment_post_ID FROM $wpdb->comments ORDER BY comment_date DESC LIMIT 0 , 30″); foreach ($ids as $id) { $post = &get_post( $id ); setup_postdata($post); ?> <p><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></p> <?php } ?> Which shows the latest commented posts in a […]

Retrieving list of a custom post type in a widget without using WP_Query?

I’m using the following widget to retrieve a list of the custom post type jobs: class FeaturedJobsWidget extends WP_Widget { function FeaturedJobsWidget() { $widget_ops = array(‘classname’ => ‘FeaturedJobsWidget’, ‘description’ => ‘Displays a random post with thumbnail’ ); $this->WP_Widget(‘FeaturedJobsWidget’, ‘Featured Jobs’, $widget_ops); } function form($instance) { $instance = wp_parse_args( (array) $instance, array( ‘title’ => ” ) […]

How would I get 1 latest post from a query for 5 posts?

So I have a wp_query which is getting the 5 most recent posts from my WordPress site. What I want to do is from within this query, grab the most recent post and show this as a sort of ‘hero’ post, and then take the other 4 posts (could be more than 4 if I […]

Undefined WP_Query::has_posts()?

This must be wrong. I was testing something so I did: $queried_post = new WP_Query(array(‘posts_per_page’ => 5, ‘offset’=> 1, ‘category’ => 1)); var_dump($queried_post->has_posts()); exit; And I get the error: Fatal error: Call to undefined method WP_Query::has_posts() I am working with this inside a class INSIDE the theme …. var_dump($queried_posts); shows 5-6 posts. even if their […]

Adding additional data to WP_Post object

I want to add additional items to the data returned as WP_Post. So for every function/query that returns a WP_Post object I want my additional data added. Example of returned result: WP_Post (object) => [ // Default data returned by WP_Post ID => int, post_author => string, post_name => string, post_type => string, post_title => […]