post_type argument not working correctly with WP_Query

Your $args array should not have the call to get_posts(). $args should just be an array: $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘page’, ‘meta_key’ => ‘top-story’, // true-false ‘meta_value’ => ‘1’ ); $the_query = new WP_Query($args);

Changing the default wp_search_stopwords

You are close: you indeed need to define a filter, but you’ve not quite gotten the filter definition right: function add_meh_stopword($stopwords) { $stopwords[] = ‘meh’; // *add* “meh” to the list of stopwords // if instead you want to completely replace the list of stopwords // use $stopwords = array(‘meh’); return $stopwords; } add_filter( ‘wp_search_stopwords’, … Read more

Co-authors list of all posts

Nevermind, I fixed it by changing query by author_name instead of ID Works! $the_query = new WP_Query( array( ‘posts_per_page’ => -1, ‘author_name’ => get_the_author_meta(‘nickname’), ) ); We can close this question!

Exclude parent with child pages from WP_Query

the_dramatist’s answer will give you only top-level pages that have no children, which matches the example given in your description. However, if you want to get ALL leaf pages, use the following: SELECT * FROM $wpdb->posts WHERE post_type=”page” AND ID NOT in ( SELECT ID FROM $wpdb->posts WHERE post_type=”page” AND ID in ( SELECT post_parent … Read more

Make a SQL query with wpdb in WordPress

The main problem is how you’re specifying the custom table name (e.g., $wpdb->cf7dbplugin_submits). $wpdb only knows about the “built-in” tables when accessing a table name via $wpdb->xxx. To specify access a custom table name, use {$wpdb->prefix}custom_table_name. The other thing I notice is that, for security purposes, you should never use interpolated variables in an SQL … Read more

WP User Query with Custom Fields and Search Results

Not sure if you ever found the answer, but just in case, I just did 🙂 There’s a hook I (finally!) found that lets you do this and works in a similar way to posts_where. The hook is pre_user_query. Here’s an example on the Codex: https://developer.wordpress.org/reference/hooks/pre_user_query/#user-contributed-notes With the above, your function could now look like … Read more

WP_Query gives me different results depending on the category order

I solved it the following way $query_args[‘tax_query’] = array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => $categories, ), ); Apparently I had to explicitely say that I was filtering through the taxonomy “category”. I could see that thanks to the comment from @birgire. Thanks man! Update As petition, this is … Read more