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.
本文标签:
版权声明:本文标题:wp query - Block Editor - Wordpress 6.1 - CPT Archive Issue - While the title changes in the loop, all records display the same 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308371a1933639.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论