How is it possible to get top comment from all children?

You could adapt get_post_acestors(), and write a similar function for comments. Here is an example that returns the top comment’s id or false. Not tested! function get_root_comment( $comment_id ) { $comment = get_comment( $comment_id ); if ( ! $comment || empty( $comment->comment_parent ) || $comment->comment_parent == $comment_id ) { return false; } $ancestors = []; … Read more

SQL query to select posts from multiple categories

I would use the built in API like Rarst mentioned. You could do something like this: $just_seven = new WP_Query( array( ‘category__in’ => array( 7 ), ‘category__not_in’ => array( 10 ) ) ); You would then have those items in $just_seven->posts. However, if you MUST use a direct SQL statement, I’d suggest using INNER JOIN … Read more

Exclude featured image and custom field from this get_attachment query

The asker refused to post his solution as answer, so I took the liberty to get this question out of our growing Unanswered Questions list … <?php $logo = get_post_meta($post->ID, ‘_lm_comm_logo’, true); $map = get_post_meta($post->ID, ‘_lm_comm_map’, true); $args = array( ‘numberposts’ => -1, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, … Read more