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

Limiting post list by taxonomy

A simple search in codex shows how to do that : $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘people’, ‘field’ => ‘slug’, ‘terms’ => ‘bob’ ) ) ); $query = new WP_Query( $args ); EDIT: do not use showposts, it’s deprecated.

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

The best way to collision check in WP

I don’t think there is a built in mechanism for searching the meta table for a key/value pair other than a full blown post search with WP_Query. I’d consider that overkill. Just query the table: $unique = $wpdb->get_var( “SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_key = ‘unique_code’ AND meta_value=”{$random}” LIMIT 1″ ); I can’t help but … Read more

Custom Homepage Pagination using WP_Query

Since it works on another page successfully, I don’t understand why it isn’t working for me here. The problem is other page is not Static Front Page. When paging a static page, WordPress use the page variable, not the paged query variable. Pages use <!–nextpage–> to paginate. From the WP_Query page: Pagination Note: Use get_query_var(‘page’); … Read more

max_num_pages says 4, yet I am only able to navigate to the third page

You’re assigning three different values to your variable: if ( get_query_var(‘paged’) ) { $paged = get_query_var(‘paged’); } else if ( get_query_var(‘page’) ) { $paged = get_query_var(‘page’); } else { $paged = 1; } Short explanation: On single.php, singular.php and other single view templates: (int) $page Is the page of the post, as specified by the … Read more