$heroes = get_posts([
'numberposts' => -1,
'post_type' => 'ffawakeheroes'
]);
if ( $heroes ) {
foreach ($heroes as $hero ) {
$field = get_fields($hero->ID);
if( strtolower($field['hero_identities']['name']) == $heroname ) : ?>
<h1>This is a <?php echo $field['hero_identities']['alias']; ?></h1>
<?php
endif;
}
}
That is the code where $heroes is a custom post type, and have many posts. What i want to get is the post if hero name has a same name attribute from the shortcode.
this is my shortcode
[heroes name=”ace”]
I don’t know if this is the right place to ask. But maybe someone can enlighten me if this code is efficient or not ?
Thank you for your help.