Added Date Filter To Popular Posts Query

For creating a date filter you can use // Create a new filtering function that will add our where clause to the query function filter_where( $where=”” ) { // posts in the last 7 days $where .= ” AND post_date > ‘” . date(‘Y-m-d’, strtotime(‘-7 days’)) . “‘”; return $where; } add_filter( ‘posts_where’, ‘filter_where’ ); … Read more

Category not being selected

The cat parameter takes an ID and not the category name or slug. If you want to use the slug you need category_name but it must be the slug. $first_query = new WP_Query(‘category_name=postblok’); Other category parameters are: cat (int) – use category id. category_name (string) – use category slug (NOT name). category__and (array) – use … Read more

How to change tag based on metabox value within $wp_query

It sounds like you’re just looking for get_post_meta(). Using your custom field of issue_number, you’ll do something like this (untested): $issue_number = get_post_meta( get_the_ID(), ‘issue_number’, true ); $my_issue_query = new WP_Query( array( ‘post_type’ => ‘issue’, ‘tag’ => ‘issue-‘ . $issue_number, ‘posts_per_page’ => 50 )); Note: While the code you pasted may work, you don’t want … Read more

WQ Query post meta date comparison

You have a bit of a problem. The only human calendar format that sorts correctly is YYYY/MM/DD, the separators are optional. You have DD/MM/YYYY. Whoever decided to store in that format made a bad decision. Your best option is to correct that design decision and convert those dates to YYYY-MM-DD or to a Unix Timestamp. … Read more

Find only those galleries with images

I believe that a relatively simple meta_query would do it. $args = array( ‘post_type’ => ‘post’, ‘meta_query’ => array( array( ‘key’ => ‘_gallery_image_ids’, ‘value’ => ”, ‘compare’ => ‘EXISTS’ ) ) ); $query = new WP_Query( $args ); Reference: http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

WP_Query orderby random do not repeat infinite scroll – one loop

I use this solution in my functions.php /*—— order ——*/ session_start(); add_filter(‘posts_orderby’, ‘edit_posts_orderby’); function edit_posts_orderby($orderby_statement) { $seed = $_SESSION[“sem”]; if (empty($seed)) { $seed = rand(); $_SESSION[“sem”] = $seed; } $orderby_statement=”RAND(“.$seed.’)’; return $orderby_statement; } And additionaly, in the page where you show the posts, in the top of the file, i reset the session variable to … Read more