Created
January 7, 2015 21:08
-
-
Save zachfeldman/78f6a9ac693d5e3b8df2 to your computer and use it in GitHub Desktop.
Advanced Custom Fields - get_post_id_from_repeater_sub_field
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
function get_post_id_from_repeater_sub_field($parent_name, $child_name, $meta_value){ | |
global $wpdb; | |
$rows = $wpdb->get_results($wpdb->prepare( | |
" | |
SELECT wp_posts.ID | |
FROM wp_postmeta | |
JOIN wp_posts | |
ON wp_postmeta.post_id=wp_posts.ID | |
WHERE wp_postmeta.meta_key LIKE %s | |
AND wp_postmeta.meta_value = %s | |
AND wp_posts.post_type != 'revision' | |
", | |
$parent_name."_%_".$child_name, // meta_name: $ParentName_$RowNumber_$ChildName | |
$meta_value // meta_value: 'type_3' for example | |
)); | |
return $rows[0]->ID; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment