• qdungeng

    (@qdungeng)


    <?php
    global $post;
    $category = get_the_category($post->ID);
    $category = $category[0]->cat_ID;
    $myposts = get_posts(array('numberposts' => -1, 'category__in' => $category));
    foreach($myposts as $post) :
    setup_postdata($post);
    ?>
    
    <?php
    $field = get_field_object('hotel_in');
    $value = get_field('hotel_in');
    $label = $field['choices'][ $value ];
    $posts = get_posts(array(
    	'numberposts' => -1,
    	'meta_key' => $field,
    	'meta_value' => $value
    ));
    
    if($posts)
    {
    	echo 'Hotel in ' .$label .'<ul>';
    
    	foreach($posts as $post)
    	{
    		echo '<li><a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a></li>';
    	}
    
    	echo '</ul>';
    }
    
    ?>
    
    <?php endforeach; ?>
    <?php wp_reset_query(); ?>

    Error to display :
    Warning: trim() expects parameter 1 to be string, array given in D:\xampp\htdocs\newdh\wp-includes\meta.php on line 774
    Please help me.

    Thanks a lot.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The call to trim() is part of a method defined in class WP_Meta_Query, and the value trying to be trimmed is $q['key']. I’m guessing your $field value is an array instead of a string. Use echo '<pre>'; print_r($field); echo '</pre>'; to examine the value. The array structure will indicate the proper reference you need to pass as the ‘meta_key’ value.

Viewing 1 replies (of 1 total)
  • The topic ‘Please help me to this code’ is closed to new replies.