query_post by title?

functions.php <?php add_filter( ‘posts_where’, ‘title_like_posts_where’, 10, 2 ); function title_like_posts_where( $where, $wp_query ) { global $wpdb; if ( $post_title_like = $wp_query->get( ‘post_title_like’ ) ) { $where .= ‘ AND ‘ . $wpdb->posts . ‘.post_title LIKE \’%’ . esc_sql( $wpdb->esc_like( $post_title_like ) ) . ‘%\”; } return $where; } ?> Then: $args = array( ‘post_title_like’ => … Read more

Page template query with WP_Query

UPDATE: This is now a decade old answer, meant for a very old version of WordPress. I can see the comments informing me that this might not work for newer WP versions, please do refer to the other answers below if mine is not working for your version of WP. For WP 2.*, this will … Read more

Order by multiple meta key and meta value [closed]

meta_query is an array of meta clauses. For example: $q = new WP_Query( array( ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘state’, ‘value’ => ‘Wisconsin’, ), array( ‘key’ => ‘city’, ‘compare’ => ‘EXISTS’, ), ), ) ); You can use an associative array, with a key for each meta clause: $q = new … Read more

Query multiple custom post types in single loop

Just change the post_type bit to: ‘post_type’ => array(‘testimonial’, ‘other_post_type’, ‘another-post-type’), Assuming that taxonomy is valid across all 3 post types. Otherwise you’ll have to leave that out. Why? You can pass an array to post_type field.

Broken? WP_Query and “attachment” as a post type

These are the query parameters i use…works for me when i loop through the results array( ‘post_parent’ => $post->ID, ‘post_status’ => ‘inherit’, ‘post_type’=> ‘attachment’, ‘post_mime_type’ => ‘image/jpeg,image/gif,image/jpg,image/png’ ); For more detail, please see official documentation for WP_Query’s status parameters

$GLOBALS[‘wp_the_query’] vs global $wp_query

You have missed one, $GLOBALS[‘wp_query’]. For all purposes, $GLOBALS[‘wp_query’] === $wp_query. $GLOBALS[‘wp_query’] is however better for readability and should be used instead of $wp_query, BUT, that remains personal preference Now, in a perfect world where unicorns rule the world, $GLOBALS[‘wp_the_query’] === $GLOBALS[‘wp_query’] === $wp_query. By default, this should be true. If we look at where … Read more

Display all posts in a custom post type, grouped by a custom taxonomy

So, you might consider automating the multiple queries. First, get the list of terms in your custom taxonomy, using get_terms(): <?php $member_group_terms = get_terms( ‘member_group’ ); ?> Then, loop through each one, running a new query each time: <?php foreach ( $member_group_terms as $member_group_term ) { $member_group_query = new WP_Query( array( ‘post_type’ => ‘member’, ‘tax_query’ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)