Skip to content

Instantly share code, notes, and snippets.

@mgratch
Created August 3, 2018 16:42
Show Gist options
  • Save mgratch/a5c486d4f9edd7e2e2b3c073fcbf1910 to your computer and use it in GitHub Desktop.
Save mgratch/a5c486d4f9edd7e2e2b3c073fcbf1910 to your computer and use it in GitHub Desktop.
Loop through all the blog posts and mark the first 4 as featured. Using variables, loops wp-cli, conditionals.
// loop through all the blog posts and mark the first 4 as featured.
i=0; \
c=4; \
for id in $(wp post list --format=ids); \
do let i++; \
if [ "$i" -lt 4 ]; \
then wp post meta update $id featured_post '1'; \
else wp post meta update $id featured_post '0'; \
fi; \
done; \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment