From ACF plugin, I select on one page using get_post($args):
$args = array(
'suppress_filters' => 0,
'posts_per_page' => -1,
'sort_order' => 'ASC',
'sort_column' => 'post_title',
'post_type' => 'my_type',
'post_status' => 'publish',
);
$my_types = get_posts($args);
Then iterating over $types I construct an < ul > of the things that are returned as my type and for each I also get the according id
foreach ($my_types as $my_type) {
$title = $my_type->post_title;
$slug = $my_type->post_name;
$thisid = $my_type->ID;
$permalink = get_permalink($thisid);
$fields = get_fields($thisid);
}
Each li get's an link to $permalink and a picture of that item: $fields['photo']
<a class="pop" href="<?php echo $permalink ?>">
Now on that $permalink-page, I again get the fields
$fields = get_fields();
ACF documentation says, get_fields "Defaults to the current post." when no ID is given.
The problem is now, that $get_fields() doesn't contain any ID. I can use an ID to get specific post, or it just gives the "current post" when no ID was given. It contains the defined ACFs but no Id I could select on.
How can I get $thisid from get_fields() so I can pass it as a parameter?
I'd need to create on each $permalink page of an item a link to a contact form which needs to get added to it's URL the ID of that thing.
<a href="/?id=<?php echo $thisid; ?>">
// ("contacts" is a CPT content type)
So I can do in the javascript on the form page perform a get_fields($id); to add stuff like name or photo from the fields to the contact form.
The only idea I have so far is to add to $permalink the ID as a get parameter:
<a class="pop" href="<?php echo $permalink ?>?id=<?php echo $thisid;?>">
And then on the $permalink page get the parameter via
$thisid = get_query_var('id');
<a href="/?id=<?php echo $thisid; ?>">
I know it's rather complex but I just want to know if there's a better way within ACF than adding the ID to each link.