Get child post ID’S
-
Greetings,
My customer has requested to not show syndicate posts in the main loop but to display them elsewhere.
I was wondering if there was a way to easily get the post ID’s that have a parent so I can filter them out?
I did manage to accomplish it using $wpdb however, I was wondering if there was already a better built in way? I wasn’t able to find anything regarding this.
Current Code(I realize it may be nasty it’s just for testing purposes):
add_action('pre_get_posts','alter_query'); function alter_query($query) { global $wp_query, $wpdb, $synposts; $blog_id = get_current_blog_id(); $db = $wpdb->base_prefix . '_3wp_broadcast_broadcastdata'; $syndicatePosts = array(); $syndicateDB = $wpdb->get_results( " SELECT post_id, data FROM $db WHERE blog_id = $blog_id " ); foreach($syndicateDB as $syn_post){ $syn_data = unserialize(base64_decode($syn_post->data)); if(isset($syn_data['linked_parent'])){ $syndicatePosts[] = $syn_post->post_id; } } $synposts = $syndicatePosts; if ( !$query->is_main_query() ) return; $query-> set('post__not_in' , $synposts ); }Thank you for your time.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Get child post ID’S’ is closed to new replies.