Iterate over objects (WP-CLI): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
(Nieuwe pagina aangemaakt met 'I feel perplexed that there seem to be no obvious way to be to iterate over a collection of objects, like posts or taxonomy terms. To add insult to injury: WP-CLI c...')
 
Regel 1: Regel 1:
 
I feel perplexed that there seem to be no obvious way to be 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.
 
I feel perplexed that there seem to be no obvious way to be 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:
+
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:
  
 
<pre>
 
<pre>
Regel 15: Regel 15:
 
* I tend to rewrite the mapfile line to <code>mapfile -t j < <( wp db query "$i" --skip-column-names | grep . )</code>, but it doesn't seem necessary here.
 
* I tend to rewrite the mapfile line to <code>mapfile -t j < <( wp db query "$i" --skip-column-names | grep . )</code>, but it doesn't seem necessary here.
 
* <code>--skip-column-names</code> is a ''mysql Client option'' → https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html
 
* <code>--skip-column-names</code> 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.

Versie van 3 nov 2022 19:15

I feel perplexed that there seem to be no obvious way to be 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 optionhttps://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.