Reputation: 4100
I'm writing a custom shortcode for a childtheme that I've dropped into my child themes functions.php. Here's the code:
function get_featured_video(){
$video_query = new WP_Query('category_name=videos&order=ASC');
$videoPath = "/";
$videoText = "";
while ($video_query->have_posts()){
$video_query->the_post();
$featured = get_post_meta($post->ID, "vid_feature", $single = true);
if(strtolower($featured)=='yes'){
$videoPath = get_permalink($post->ID);
$content = strip_tags($post->post_content);
$contentArr = str_word_count($content,1);
if(count($contentArr>50)){
$videoText = join(" ",array_slice($contentArr,0,50));
$videoText .= " <a href='$link'><read more></a>";
} else {
$videoText = $content;
}
break;
}
}
$returnStr = "<h1><a href='$videoPath'>You've Got to See This!</a></h1>\n";
$returnStr .= $videoText;
return $returnStr;
}
add_shortcode('getfeaturedvideo','get_featured_video');
The problem I'm having is that it's returning a blank query. I know there's a post in the videos category. I've never used the WP_Query inside functions.php. Is there a different method I need to use?
Upvotes: 1
Views: 5085