List custom taxonomy terms from custom field

The problem you are facing is that get_the_terms() returns an array (or false or a WP_Error-Object), not a string. So, assuming that you have multiple terms for images, you could use a code like this: if( $labels && !is_wp_error( $labels ) ) { foreach( $labels as $label ) { $labelarray[] = $label->name; } $labelstring = … Read more

If category then echo a custom fields

Use the in_category() function, like this: <?php if ( in_category( 4 ) ) : ?> <div class=”event-post-icons”> <ul> <li class=”single-post-date”><?php the_field(‘event_date’); ?></li> <li class=”single-post-time”><?php the_field(‘event_time’); ?></li> <li class=”single-post-price”><?php the_field(‘booking_fee’); ?></li> <li class=”single-post-palce”><?php the_field(‘event_location’); ?></li> </ul> </div><!– /event-post-icons –> <?php endif; ?> If you are using this to test a post outside of The Loop, you … Read more

Query post order by post and desc not working

post is not a valid value for orderby parameter neither DESC. You can choose any of these values. Also, you should stop using query_post. <?php $args = array( ‘post_type’ => ‘ranking’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘DESC’, ‘posts_per_page’ => 10, ‘meta_key’ => ‘top10’, ‘meta_value’ => ‘sim’ ); $loop = new WP_Query( $args ); while ( … Read more

Understanding and using metaboxes in posts

To save: // Update and save the field so it can be used in our template if ( isset( $_POST[‘input_name’] ) ) { $data = sanitize_text_field( $_POST[‘input_name’] ); update_post_meta( $post_id, ‘field_name’, $data ); } To read: $data = get_post_meta( $post_id, ‘field_name’, true ); // With post object, a leaner, cleaner method: $data = $post->field_name; There’s … Read more

Use custom field as a variable

You are using the_ID() instead of get_the_ID(). Which is being echo. Also why you are using so many variable and pulling all the meta keys. I would like to suggest this code using get_post_meta(). $my_custom_field = get_post_meta(get_the_ID(), ‘app_collection-postcode’, true); $my_custom_field2 = get_post_meta(get_the_ID(), ‘app_delivery-postcode’, true); $url = “http://maps.googleapis.com/maps/api/distancematrix/json?origins=$my_custom_field&destinations=$my_custom_field2&mode=driving&language=en-EN&sensor=false”; $data = @file_get_contents($url); $result = json_decode($data, true); foreach($result[‘rows’] … Read more

Json api does not return all metadata

As @TheDeadMedic mentioned the API will exclude any meta with underscore. It’s not a good idea to remove the underscore as it might break something in your code or dependencies, however you can try adding a code like this in your functions.php to unprotect the desired meta add_filter( ‘is_protected_meta’, ‘wp692_meta_unprotect’, 10, 2 ); function wp692_meta_unprotect( … Read more