I have:
- Wordpress custom post types;
- Two hotels registered in the custom Wordpress admin area;
- A variable named
$hotelswhich get the field where the hotels registered are listed;
For the $hotels, I'm using the get_field property that is works like an array. Inside this array, I have to get the name of the post (which is the name of the hotel). I'd like to search into the array the name of the hotel and print it in the page.
If I code:
<?php
$hotels = get_field('produtos_hotel');
print_r($hotels);
$key = array_search('Ocean Maya Royale', $hotels);
echo $key; // should display 'Ocean Maya Royale';
?>
It will output this mess:
Array (
[0] => WP_Post Object (
[ID] => 1113
[post_author] => 1
[post_date] => 2014-06-11 16:18:59
[post_date_gmt] => 2014-06-11 19:18:59
[post_content] =>
[post_title] => Ocean Maya Royale
[post_excerpt] =>
[post_status] => publish
[comment_status] => open
[ping_status] => open
[post_password] =>
[post_name] => ocean-maya-royale
[to_ping] =>
[pinged] =>
[post_modified] => 2014-06-18 14:41:25
[post_modified_gmt] => 2014-06-18 17:41:25
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://localhost/mydocs/advtour/newsite/wordpress/?post_type=add_content&p=1113
[menu_order] => 0
[post_type] => add_content
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[1] => WP_Post Object (
[ID] => 1302
[post_author] => 1
[post_date] => 2014-06-12 01:19:36
[post_date_gmt] => 2014-06-12 04:19:36
[post_content] =>
[post_title] => Flamingo Cancun Resort
[post_excerpt] =>
[post_status] => publish
[comment_status] => open
[ping_status] => open
[post_password] =>
[post_name] => flamingo-cancun-resort
[to_ping] =>
[pinged] =>
[post_modified] => 2014-06-18 14:40:19
[post_modified_gmt] => 2014-06-18 17:40:19
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://localhost/mydocs/advtour/newsite/wordpress/?post_type=add_content&p=1302
[menu_order] => 0
[post_type] => add_content
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
)
Can you guys see the [post_title] element? So, I have to take the Ocean Maya Royale or the Flamingo Cancun Resort, but the array_search can not find it!
Thank you!
$hotels['post_name']$hotels[$id]['post_name']