Displaying a custom field

get_post_custom() will return an array of arrays. You need: echo $custom_array[‘my_custom_field’][0]; Alternatively, you can use get_post_meta() with the $single flag as true: echo get_post_meta( get_the_ID(), ‘my_custom_field’, true );

Display Multiple Values of Same Key

<?php // get an array of multiple values $post_meta_array = get_post_meta($post->ID, ‘link’); // do not use ‘true’ as the third argument // echo the link for each value foreach ($post_meta_array as $post_meta) { echo ‘<a href=”‘ . $post_meta . ‘” target=”_blank”>Images Source</a>’; }

get posts where a custom field contains a text

Here are few ideas: 1) You could try to compare with LIKE instead: ‘key’ => ‘_my_custom_field_key’, ‘value’ => ‘test1’, ‘compare’ => ‘LIKE’ It should give you a SQL query with: … LIKE ‘%test1%’ … 2) You might want to save the string as ,test1,test2,test3, to make the whole word search easier: ‘key’ => ‘_my_custom_field_key’, ‘value’ … Read more

Search posts missing a particular custom field

Try using ‘NOT EXISTS’ instead of ‘NOT LIKE’ and remove the value ( it’ll be removed by WP with NOT EXISTS ): $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 5, ‘meta_query’ => array( array( ‘key’ => ‘verified’, ‘compare’ => ‘NOT EXISTS’ ) ) ); $query = new WP_Query( $args ); http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

Hook after meta created

There is a dynamic hook right before any new metadata is added: do_action( “add_{$meta_type}_meta”, $object_id, $meta_key, $_meta_value ); It would be add_post_meta for posts accordingly. Note that you might to tinker some to catch this precisely in the case of new post being created, for example hook into publish_post first, note the ID, and add … Read more

WordPress implode & wp_insert_post question

The second parameter to wp_set_object_terms() takes an array, integer, or string. (array/int/string) (required) The slug or id of the term (such as category or tag IDs), will replace all existing related terms in this taxonomy. To clear or remove all terms from an object, pass an empty string or NULL. Integers are interpreted as tag … Read more

Sort WP_Query with numeric custom field

Your meta key should be specified as the meta_key argument, and orderby should be meta_value_num: $args = array( ‘post_type’ => ‘post_sermons’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => ot_get_option(‘wpl_sermon_per_page’), ‘paged’=> $paged, ‘meta_key’ => ‘video_order’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’ ); See WP_Query for explanations of query arguments.