Filter or order based on custom field

I have added a custom field to some posts called ‘frontpagerank’ Then shouldn’t the WP_Query args reference that key then, eg. ‘meta_key’ => ‘frontpagerank’ If i follow, you want to check for posts that have this key, and you’re expecting a numeric value, so i’ll naturally assume you don’t want posts with this key(but an … Read more

Change Page Order by Custom Field (Magic Fields)

I tested this code and it works great: <?php query_posts(‘meta_key=price&orderby=meta_value_num&post_parent=”.$post->ID.”&post_type=page’); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class=”page” id=”post-<?php the_ID(); ?>”> <div class=”pagecontent”> <div class=”grid”> <a href=”https://wordpress.stackexchange.com/questions/13375/<?php the_permalink(); ?>” title=”<?php the_title(); ?>”> <?php $attachments = get_children( array ( ‘post_parent’ => $post->ID, ‘post_type’ => ‘attachment’, ‘numberposts’ => 1, … Read more

Getting and calculating averge value of custom fields of the same tag

If its a regular custom field you can add this to your archive.php: //before the loop $rating_count = 0; $total_rating = 0; //in the loop $total_rating = $total_rating + get_post_meta($post->ID,’your_custom_field_name’,true); $rating_count = $rating_count + 1; //after the loop: $average = $total_rating / $rating_count; echo ‘the average rating for this tag is: ‘ . $average; Update … Read more

Counting post fields

You can do custom query loop for that particular meta box for an empty value. Something along the lines of $check_city_value = get_post_meta($post->ID, ‘city_box’); ?> if (empty($check_city_value)) { echo ‘$check_city_value is either 0, empty, or not set’; } You would have to loop through all the posts to do this and for multiple meta box … Read more

How to automatically change a posts status to draft based on custom field

For cron jobs, take a look at the Transients API. The rest could maybe be acchieved with something like the following. I have never ever used the transient API before and code’s not tested. function set_post_to_draft() { global $post; if ( get_post_meta( $post->ID, ‘set_to_draft_key’ ) == true ); return $post->post_status == ‘draft’; } set_transient( ‘post_to_draft_transient’, … Read more

Odd functions.php issue in WordPress

There is no WordPress function called meta(). Try using get_post_custom() (Codex ref) instead. For example: //Address add_action( ‘woo_post_inside_before’, ‘my_address’ ); function my_address() { if ( is_single() && in_category(‘listings’) ) { global $post; $meta = get_post_custom(); echo ‘<h1>’ . $meta[‘address’] . ‘</h1>’; } } Note: I’m not sure you need to call global $post; in this … Read more