Skip to content

Instantly share code, notes, and snippets.

@kmwalsh
Created September 13, 2024 18:10
Show Gist options
  • Save kmwalsh/89562fd8468fd91c68d84d10f17988cb to your computer and use it in GitHub Desktop.
Save kmwalsh/89562fd8468fd91c68d84d10f17988cb to your computer and use it in GitHub Desktop.
mysql query to get post ID, title, etc. from wp postmeta where you have flexible content with a numeric ID value
/**
* - Flexible Content created with ACF
* - Field that lets you select a Gravity Form, loads the GF ID for use in templates (can replace this with whatever, as long as the meta value assignment is to an ID)
* - Query lets you get a list of all posts using the flex content to display the form
*/
SELECT DISTINCT ID, post_title, post_status, guid, meta_value from `wp_posts`
LEFT JOIN `wp_postmeta` ON `post_id` = `ID`
WHERE `post_status` = 'publish' AND `meta_key` LIKE '%gravity_form%' AND `meta_value` REGEXP '^[0-9]+$';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment