Trying to use WP_Query to return post with and without meta values

You use both ‘meta_key‘ and ‘meta_query‘ – it is a wrong usage. Remove this code: ‘meta_key’ => ‘date’, and try again. After remove $cat WP produce sql query: SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) INNER JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id) WHERE 1=1 AND wp_posts.post_type=”post” AND (wp_posts.post_status=”publish”) … Read more

How to query term_id of a Custom Taxonomy by name

You can use the get_term_by function. This allows you to obtain a term (from a given taxonomy) by its slug or name (or id). The returned term object contains the term’s ID. For example: $term =get_term_by( ‘name’, ‘December-12’, ‘Birthday’); $term_id = $term->term_id; If ‘December-12’ is the slug, rather than the name, of the term, simply … Read more

Change Query Arguments (filter) with jQuery/Ajax or PHP?

The permalink structure you’ve described above e.g…./hotels/hamburg/features/sea-face isn’t really something that could be achieved by using custom fields. You would be better off creating a new taxonomy called ‘features’ and populating it with terms like ‘sea-facing’ and any others. In order to do queries for multiple taxonomies I would recommend the excellent Query Multiple Taxonomies … Read more

How can I query the db to access current post information?

The correct way: $my_query = new WP_Query(‘posts_per_page=2′); while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php global $post; print_r($post); // <– this is your postStuff ?> <?php endwhile;?> <?php wp_reset_query(); ?> Normally, you dont’t need to globalize the post. There are helper functions that should be used instead to fetch information from the current post

Creating a widget that displays the content of a page

If you hard-coded your custom query directly in the page template, then you’re going to need to duplicate that custom query in a custom Widget. On the other hand, if you’ve abstracted the custom query (either into a template-part file, or better yet, a custom function), then you can simply include the template-part file or … Read more