meta fields for the whole wordpress site

You are talking about “Options”. These are saved in the *_options table and can be stored and retrieved using a number of Core functions (straight from the Codex page above): Add/Delete Option add_option() delete_option() add_site_option() delete_site_option() Get/Update Option get_option() update_option() get_site_option() update_site_option()

WP Query – Is this correct?

I am guessing but based on your choice of placeholder names in the code above… $args = array( ‘meta_key’ => ‘myvalue’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’ ); … your meta_key argument is wrong. That is the meta key not the meta value as your naming convention suggests. meta_key (string) – Custom field key. http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters … Read more

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

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

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.