Iterate over objects (WP-CLI): verschil tussen versies
Naar navigatie springen
Naar zoeken springen
Regel 1: | Regel 1: | ||
− | + | There seems to be no obvious way to iterate over a collection of objects, like posts or taxonomy terms. To add insult to injury: WP-CLI commands that return object-IDs, are often limited to max. 100 items at a time. | |
Currently, this seems a quite good approach. It's only two lines of code, and it is much faster than using a 100% WP-CLI approach: | Currently, this seems a quite good approach. It's only two lines of code, and it is much faster than using a 100% WP-CLI approach: |
Versie van 3 nov 2022 19:53
There seems to be no obvious way to iterate over a collection of objects, like posts or taxonomy terms. To add insult to injury: WP-CLI commands that return object-IDs, are often limited to max. 100 items at a time.
Currently, this seems a quite good approach. It's only two lines of code, and it is much faster than using a 100% WP-CLI approach:
i='select term_id from wp_terms join wp_term_taxonomy using (term_id) where taxonomy like "pa_as%"' mapfile -t j < <( wp db query "$i" --skip-column-names ) echo ${j[@]} echo "# of entries: ${#j[@]}" echo ${!j[@]} echo "Entry 5: ${j[5]}"
- I tend to rewrite the mapfile line to
mapfile -t j < <( wp db query "$i" --skip-column-names | grep . )
, but it doesn't seem necessary here. --skip-column-names
is a mysql Client option → https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html- It's so simple, that I don't even see the point of turning this into a function to be incorporated in some general WP-CLI-Bash library.