get_post_meta just returns Array

When you set the third parameter of get_post_meta() to false, it returns an array of all the values mapped to that key – setting this parameter to true returns a single value. So your code is correct. You’d get the exact same thing if you did something like this: $test = array( “1”, “2”, “3” … Read more

Calling custom fields for pages (not posts)

try using get_metadata(‘post’, $postid, ‘teaser-text, true); these two actually same. should not make any difference. earlier i gave wrong arguments. var_dump() will show you what it is actually getting. please make sure, the ID is correct, ‘teaser-text’ exists. You can also try using some other meta name (for testing purpose only).

Ordering posts by date custom field

In your $args array, “meta_key” should be “event_time”. If you want to get events after a certain date you also have to set meta_value to the desired date and meta_compare to >, <, etc.. Note however that you’re not going to be able to order the posts with the format “June 6 2012 6:00 PM”, … Read more

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; }

Delete all custom fields at once?

You can use the SQL way. Go in your database tool, like phpMyAdmin or Adminer (also possible via Plugin in the WordPress back-end). Use the SQL area for creating custom queries. Before you start, create a backup of the database and also a single backup for the table _postmeta. Change the string wpbeta_2 to your … Read more

How to add a Custom Meta Box for more than one Post Type?

Whenever in doubt about a WordPress function, consult the Codex. http://codex.wordpress.org/Function_Reference/add_meta_box There, you’ll see that you need to add one meta box to each post type. add_action( ‘add_meta_boxes’, ‘myplugin_add_custom_box’ ); function myplugin_add_custom_box() { add_meta_box( ‘myplugin_sectionid’, __( ‘My Post Section Title’, ‘myplugin_textdomain’ ), ‘myplugin_inner_custom_box’, ‘post’ ); add_meta_box( ‘myplugin_sectionid’, __( ‘My Post Section Title’, ‘myplugin_textdomain’ ), ‘myplugin_inner_custom_box’, … Read more