Created
May 5, 2018 17:06
-
-
Save hwkdev/a64ded2d0761d24101a07549812a7d30 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
add_filter('posts_results', 'hwk_post_object_extend', 10, 2); | |
function hwk_post_object_extend($posts, $query){ | |
if(empty($posts)) | |
return $posts; | |
foreach($posts as $post){ | |
// Post Type = post | |
if(get_post_type($post) != 'post') | |
continue; | |
// Add terms to WP_POST | |
$post->my_terms = false; | |
if($terms = get_the_terms($post->ID, 'my_taxonomy')) | |
$post->my_terms = $terms; | |
// 'Single' view only | |
if($query->is_single()){ | |
// Add post meta data | |
$post->my_meta = false; | |
if($meta = get_post_meta($post->ID, 'my_meta_key', true)) | |
$post->my_meta = $meta; | |
} | |
} | |
return $posts; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment