admin管理员组

文章数量:1122846

I am using the block editor with CPT. I have a loop that iterates though my CPT. The title changes for each record but not the data in the CPT. I am using a shortcode to display my custom post type data. Will I need to pass the post id to the short code? How can I get CPT data in an archive loop please?

function fs_ski_resort_field_fn($attr){
    $key = shortcode_atts(array(
        'key' => ''
        ), $attr);
        // get the acf key
        $the_value_of_fs_field = get_acf_key($key['key']);
        return $the_value_of_fs_field;
}

add_shortcode('fs_ski_resort_field', 'fs_ski_resort_field_fn');
function get_acf_key($key){

$fs_ski_resort_data = get_field('field_64b38c4e3ec56', $post_id ); 

switch ($key) {
       case 'name':                    
          $result = $fs_ski_resort_data['fs_name'] ?: $fs_ski_resort_data['osm_name']; 
          break;
}
return $result;

}

I then call the shortcode in

[fs_ski_resort_field key="name"]​

Above shortcode is in: archive-fs_ski_resorts.html

I have about 300 records. "name" repeats the first record's name 300x.

本文标签: