最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)

programmeradmin3浏览0评论

How can I write a WordPress meta query that gives me an array of users/posts that have a given amount of entries in a custom field that stores multiple values?

Something like SQL COUNT(), but for the number of entries in an ACF array field.

When writing a WP_Meta_Query and comparing with >, >=, etc. this doesn't seem to work for me, perhaps because the data is stored serialized.

So, basically, how can I perform a simple selection of records with a specific count inside their custom field value.

How can I write a WordPress meta query that gives me an array of users/posts that have a given amount of entries in a custom field that stores multiple values?

Something like SQL COUNT(), but for the number of entries in an ACF array field.

When writing a WP_Meta_Query and comparing with >, >=, etc. this doesn't seem to work for me, perhaps because the data is stored serialized.

So, basically, how can I perform a simple selection of records with a specific count inside their custom field value.

Share Improve this question asked Jan 24, 2022 at 19:20 David WolfDavid Wolf 2833 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

This isn't possible using WP_Query, you can't query the insides of structured data stored in a single post meta value.

At best you can use regular expressions, or do math/boolean comparisons, you can even do LIKE comparisons, but these are all string operations.

If you need to query structured data such as objects or arrays, then the data needs breaking apart into multiple separate post meta values.

At the end of the day, post meta values are just strings of text as far as the database is concerned. You can cast them to a different basic data type such as a date or number, but that's it.

发布评论

评论列表(0)

  1. 暂无评论