trim custom field text value and show (…)

building on keatch’s answer you only need to trim if its longer the 25 chars so: $trim_length = 25; //desired length of text to display $custom_field = ‘my-custom-field-name’; $value = get_post_meta($post->ID, $custom_field, true); if ($value) { if (strlen($value) > $trim_length) $value = rtrim(substr($value,0,$trim_length)) .'(…)’; echo $value; }

query posts and custom post type with meta key

I’m afraid WP_Query is not able to fetch (Posts with custom field) or (ailec_even). You’ll have to query the firs one, than the second one and merge those arrays. Use WP_Query instead of query_posts. I’ve just tried it on my local installation and this code called from index.php of twentytwelve works (brings post with title … Read more

How to sort category by custom field value

Your question it make sense to me my friend but the get_categories don’t have the option to order by “meta_value_num” and then order by custom fields. What you can do is order after you get the array using the usort php function: $all_subcategories = array(‘parent’ => $categoryID); $categories = get_categories( $all_subcategories ); function order_categories($a, $b) … Read more

Ordering Posts Type A by Custom Fields of related Post Type B

This works. The filters are tied to a custom ‘orderby’ term and removed after the query. $args = array( ‘post_type’ => ‘artworks’, ‘posts_per_page’ => -1, ‘no_found_rows’ => true, ‘order’ => ‘ASC’, ‘orderby’ => ‘artist_name_artwork_title’, ); add_filter(‘posts_join’, ‘name_join’, 10, 2 ); add_filter(‘posts_orderby’, ‘orderby_artist_name_artwork_title’, 10, 2); // query $wp_query = new WP_Query( $args ); remove_filter(‘posts_join’, ‘name_join’, 10 … Read more

Custom WP Query from meta_value stored as serialised array

If you’re inside the while loop, use get_the_ID(). // returns an array as this is a multicheck field in Magic Fields 2 if(get_post_meta(get_the_ID(), ‘services’, true)){ $services = get_post_meta(get_the_ID(), ‘services’, true); $services = maybe_unserialize($services); // foreach item in the array foreach ($services as $service) { if ( sanitize_title($service_title) == sanitize_title($service) ) { echo ‘<p>’ . esc_attr($service) … Read more

How to use Meta Value Compare in WP_Query For Max and Min numbers

This looks right, I have very similar code that works as expected: function price_query_test() { update_post_meta( 7, ‘_price’, 10 ); update_post_meta( 12, ‘_price’, 20 ); update_post_meta( 18, ‘_price’, 30 ); update_post_meta( 72, ‘_price’, 40 ); $test = new WP_Query( array( ‘post_type’ => ‘page’, ‘meta_query’ => array( array( ‘key’ => ‘_price’, ‘value’ => array( ’10’, ’25’ … Read more