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

Any way to include custom fields in WP_Query results?

You may want to hook somewhere in the gazillion hooks available in wp-includes/query.php. I would suggest something like this: function my_always_get_post_custom( $posts ) { for ( $i = 0; $i < count($posts); $i++ ) { $custom_fields = get_post_custom( $posts[$i]->ID ); $posts[$i]->custom_fields = $custom_fields; } return $posts; } add_filter( ‘the_posts’, ‘my_always_get_post_custom’ ); In this way you … Read more

Upcoming Event: How do I sort database by custom date field, but ignore past dates?

You’re pretty close, but I wouldn’t be distracted by the ‘scope’ meta key. The following is untested. <?php $args = array( ‘post__not_in’ => array($donotrepeat), “post_type” => ‘event’, ‘meta_key’ => ‘_event_start_date’, // name of custom field ‘orderby’ => ‘meta_value’, “order” => ‘ASC’, “posts_per_page” => 1, ‘meta_query’ => array( array( ‘key’ => ‘_event_start_date’, ‘value’ => date(‘Y-m-d’), ‘compare’ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)