What is appropriate flow for custom data from URL in WP_Query?

I think the WP function you are looking for is add_rewrite_tag. It aims to add custom GET params to your URL and include it automatically in query_vars. For example, you can add the following to the init hook : add_rewrite_tag(‘%person%’,'([^&]+)’); For a url like http://example.com?person=joe, the global $wp_query will have $wp_query->query_vars[‘person’] = ‘joe’ You can … Read more

Passing and retrieving query vars in wordpress

I’m almost sure that author is built-in, so use something like author_more. You will need to add that var to query_vars first. Example: // add `author_more` to query vars add_filter( ‘init’, ‘add_author_more_query_var’ ); function add_author_more_query_var() { global $wp; $wp->add_query_var( ‘author_more’ ); } Then on your more-author-posts.php template call it like this: if ( get_query_var( ‘author_more’ … Read more

Query posts only with featured image

When running the importer, you must check the checkbox to download and import all media/attachments. If you do not, the posts will still have a featured image set, but the attachment they refer to will be invalid, and any attempt to call the_post_thumbnail will fail. Using your code you would get just the post title, … Read more

meta_query ‘compare’ => ‘IN’ not working

There’s no easy way to search serialized values in a meta query. If the list of values isn’t crazy long, potentially you could set up multiple meta queries: ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘system_power_supply’, ‘value’ => ‘single’, ‘compare’ => ‘LIKE’, ), array( ‘key’ => ‘system_power_supply’, ‘value’ => ‘redundant’, ‘compare’ => ‘LIKE’, … Read more

How to use a custom post type archive as front page?

After you have set a static page as your home page you can add this to your functions.php and you are good to go. This will call the archive-POSTTYPE.php template correctly as well. add_action(“pre_get_posts”, “custom_front_page”); function custom_front_page($wp_query){ //Ensure this filter isn’t applied to the admin area if(is_admin()) { return; } if($wp_query->get(‘page_id’) == get_option(‘page_on_front’)): $wp_query->set(‘post_type’, ‘CUSTOM … Read more

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

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