Query Custom Post Type by Tag
Ahhh.. not sure why I didn’t think to use tax_query. A friend figured it out. Gist is updated.
Ahhh.. not sure why I didn’t think to use tax_query. A friend figured it out. Gist is updated.
$args = array( ‘author’ => 1, ‘numberposts’ => 1 ); The author parameter isn’t documented on the get_posts() codex page, but it does work.
Yeah, I did something like this recently, but this is how I did it: $showNum = 10; $startNum = 0; if($paged > 0){ $pageNum = $paged – 1; $startNum = $pageNum * $showNum; } elseif($paged == 0){ $paged = 1; } Then I went ahead and used the modified $paged value to request entries within … Read more
Answering my own question, as suggested in my edit I’ve had to use the following meta_query array to query the posts: ‘meta_query’ => array( array( ‘key’ => ‘country’, ‘compare’ => ‘LIKE’, ‘value’ => ‘”‘ . get_the_ID() . ‘”‘ ) )
If you want to plug into the query, pre_get_posts() is going to be your friend. Pippin Williamson also has a great writeup on the subject.
Are the queries themselves displayed or are the results displayed? If the results of those queries are being output onto your homepage it’s a potential security vulnerability. The query returns user data including username and password hash for user ID 1 of the wp_users table, which is the administrator user that WordPress creates when first … Read more
You can do this by just looking for release_date_db: function plugin_name_get_posts() { global $wpdb; $the_posts = $wpdb->get_results( “SELECT * FROM $wpdb->posts, $wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND meta_key = ‘release_date_db’ AND meta_value >= 20120000 AND meta_value <= 20121231 ORDER BY meta_value ASC;”, ARRAY_A ); }
I believe the query var that you are retrieving should be paged and not page. See the codex and adjust your query to the following: $products_query = new WP_Query(array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 4, ‘paged’ => (get_query_var(‘paged’) ? get_query_var(‘paged’) : 1), )); However, if this is an archive for your product post type why … Read more
This loop looks pretty sure to me. You aren’t exposing any raw SQL anywhere, so injection attacks shouldn’t happen.
You must first do the 4 queries for selected categories and while looping through them remember the IDs. Save them in an array. Then when pulling latest posts just add the post__not_in parameter with all the IDs you want to exclude. You need 4 queries that look somewhat like this: $args = array( ‘category_name’ => … Read more