How to display related posts by same publish date?

Get the date of current post: $date = get_the_date(‘Y-m-d’); Get year, month and day from the $date variable. $exploded = explode(‘-‘, $date); $year = $exploded[0]; $month = $exploded[1]; $day = $exploded[2]; Lastly, query the posts that has the same publish date. $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘date_query’ => array( array( ‘year’ … Read more

Query Posts By Post Publish Date, but sort by Custom Meta Key

As you’ve discovered, meta queries only work with the post meta table, it is indeed looking for a meta key of post_date. You can’t do timespan queries with a simple query, but we can accomplish this with a combination of a query for the meta key, and a posts_where filter directly on the SQL to … Read more

Order query by post meta value

Take a look at the WordPress Codex: http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_orderby function edit_posts_orderby($orderby_statement) { $orderby_statement = “meta_value DESC”; return $orderby_statement; } add_filter(‘posts_orderby’, ‘edit_posts_orderby’); If you’re making the WP_Query yourself you can change the orderby parameter to meta_value Take a look here: http://codex.wordpress.org/Class_Reference/WP_Query

WordPress Loop: List All Posts by a Category & Subcategory

The cat and category_name parameters for WP_Query display “posts that have this category (and any children of that category)”. There are also examples of doing this in the Codex. $query = new WP_Query( ‘cat=4’ ); // or $query = new WP_Query( ‘category_name=staff’ ); I am not 100% sure what you mean by “I need all … Read more

Make one query for adding entries to database

Is there a $wpdb method available that will allow me to create the query, by looping through my query, and then execute it once I’m out of that loop? If you and your loop can construct the proper SQL, then use $wpdb->query. You can run any query you want with that, so whatever version of … Read more

What’s wrong with my $wpdb prepare?

These look like 2 separate questions. The first I think is a single vs double quotes issue: Try this: $html=””; foreach ( $recent_across_network as $post ) { $html .= ‘blog_id, ‘.$post->ID.’ ) . ‘”>’ . $post->post_title . ”; } $html .= ”; The line in the foreach is putting $post->ID in single quotes which won’t … Read more

How to retrieve elements from another table in a SQL query?

With a WP_Query() you can have all of them what you want in an easy way. See all the arguments available in the Codex. With the following code, we are grabbing all(-1) the posts from wp_posts table, and using the post ID we are grabbing the postmeta items. <?php $productquery = new WP_Query( array( ‘post_type’=>’wpcproduct’,’post_status’=>’publish’,’posts_per_page’=>-1 … Read more