How to output meta_key in wp_postmeta?

If you want to get post meta, then you just need to call get_post_meta() function and pass three arguments: current post id, your meta key and true value (what indicates that you want to receive only one value in return). Simply call echo get_post_meta( get_the_ID(), ‘_su_description’, true ); in your template and your meta value … Read more

widget exclude post by custom field

The meta_query parameter in WP_Query allows you to query posts that don’t have a certain custom field. Furthermore, you can check for multiple custom fields. With two queries in meta_query, you can fetch all posts that either don’t have a custom field, or have it set to 0: ‘meta_query’ => array( ‘relation’ => ‘OR’, array( … Read more

Query to get all the posts of more than 2 meta_value having same meta_key?

From the codex http://codex.wordpress.org/Class_Reference/WP_Query: $args = array( ‘post_type’ => ‘my_custom_post_type’, ‘meta_key’ => ‘age’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘age’, ‘value’ => array(3, 4), ‘compare’ => ‘IN’, ) ) ); $query = new WP_Query($args); Look at the meta_query section. you can define the key and then all the possible … Read more

Automatically delete posts based on query

Here is what I ended up with: Basically, I had the logic of the timing at the bottom wrong. Figuring out times and dates and what note is hard… add_action(‘init’, ‘delete_unclaimed_apps’); function delete_unclaimed_apps() { $availapps = get_posts(array( ‘post_type’ => ‘appointment’, ‘post_status’ => ‘publish’, ‘meta_query’ => array ( array( ‘key’ => ‘app_status’, ‘value’ => ‘available’, ), … Read more

WordPress loop based on url sting

use $_GET[‘Price’] and $_GET[‘Region’] to get the price and region values from the url and add them to your query args. It is rather hard without any code to start from, but try something like $queryPrice = (strpos($_GET[‘Price’],’-‘) ? explode(‘-‘, $_GET[‘Price’]) : array($_GET[‘Price’], $_GET[‘Price’])); $queryRegion = $_GET[‘Region’]; $args = array( // all your args here … Read more

Cannot order by in WP_Query

Ok, the problem came from the fact I was looping on categories to get the matching post. What I had to do was to get the desired categories and use it in my $args + some adjustments. <?php // Get the parent cat thanks to the page’s cat slug $parent_cat = get_category_by_slug( $cat[1] ); $cats_args … Read more