无限的自定义字段WordPress

如何为WordPress创建无限的自定义字段?

我想创建下载框, 但我不知道用户有多少部分。

$file1 = get_post_meta($post->ID, '1', true);
$file2 = get_post_meta($post->ID, '2', true);
$file3 = get_post_meta($post->ID, '3', true);
$file4 = get_post_meta($post->ID, '4', true);
....

#1


请考虑使用ACF插件。

你可以通过创建重复字段以及以这种方式设置和更新这些字段来实现此目的

$array_of_parts = get_fied('your-field-name', $post->ID);

Or

$array_of_parts[] = 'your-new-part';
update_field('your-field-name', $array_of_parts, $post->ID);

那么你可以使用foreach遍历这些部分, 并通过调用获得部分的数量

count( $array_of_parts )

或使用循环

for($i=1;$i<=1000;$i++){
    $file = get_post_meta($post->ID, $i, true);
    if(!empty($file)){
        echo $file;
    }else{
        break;
    }
}

来源:

https://www.srcmini02.com/64014.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37535.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?