Last active
May 10, 2023 13:12
-
-
Save michael-sumner/a6ee31ebadf8a1c4902e9527b57311fe to your computer and use it in GitHub Desktop.
This script prompts the user to enter a postmeta key to search for, and then retrieves the value of that postmeta key for each post on your WordPress site using the WP-CLI command wp post meta get. If the postmeta value is not "null", then the script prints the post ID to the console. This script allows you to quickly find all posts on your site…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Prompt the user to enter a postmeta key to search for | |
read -p "Enter the postmeta key to search for: " postmeta_key | |
# Find all posts with the specified postmeta key | |
post_ids=$(wp post list --format=ids) | |
for id in $post_ids | |
do | |
meta_value=$(wp post meta get $id $postmeta_key --format=json) | |
if [ -n "$meta_value" ] | |
then | |
echo $id | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment