统计并显示 <select> ACF 插件的值列表

huangapple go评论51阅读模式
英文:

Count and Display the List of Value of <select> ACF plugin

问题

我创建了一个名为“Country”的选择字段,选项如下:

  • 马来西亚
  • 印度尼西亚
  • 新加坡
  • 泰国
  • 缅甸

我试图在前端显示选择字段上注册的国家的总数。

期望结果:
我们连接了“5”个亚洲国家。

我尝试过:

<?php
    $number = count(get_field_objects('country'));
?>
<p>我们连接<?php echo $number; ?>个亚洲国家</p>

但是我什么都没有得到。

英文:

I create a select field called "Country" with the option:

  • Malaysia
  • Indonesia
  • Singapore
  • Thailand
  • Myanmar

And I try to show the total of the country registered on select field to my front end.

Expected result:
We connect "5" countries in Asia.

I have tried:

&lt;?php
    $number = count(get_field_objects(&#39;country&#39;));
?&gt;

&lt;p&gt;We connect &lt;?php echo country; ?&gt; Countries in Asia&lt;/p&gt;

And I've got nothing.

答案1

得分: 1

请检查我的解决方案。我也在我的一个网站上使用了相同的解决方案。您需要使用"get_field_object"函数,而不是"get_field_objects"。

$countries = get_field_object('country');
echo count($countries['choices']);
英文:

Kindly check my below solution. I have also used same solution on one of my website. You need to use "get_field_object" function instead of "get_field_objects".

$countries = get_field_object(&#39;country&#39;);
echo count($countries[&#39;choices&#39;]);

huangapple
  • 本文由 发表于 2023年4月17日 13:40:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032008.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定