0
votes

I have videos set up as a custom post type and music, commercial, promo set up as categories within this post type:

I have a function that displays a custom meta box on the videos post type pages in the wordpress back end. The user is able to enter the ID of a youtube video or the ID of a vimeo video - wordpress then displays the video for the ID on custom post type page. When a user adds a new post to the videos custom post type and assigns it to any of the categories I specify I want wordpress to display the different videos. The code I have at the moment is not doing what I want it to do because it is displaying the same video on each post even though an ID hasnt been specified on some of them. For example on the music post page I have assigned it the category music and put a vimeo video ID which is displayed on the front end but then the same video is displayed for promo and commercial and I dont want that to happen. The loop I have running this is (in single-videos.php):

<?php

$args = array( 'post_type' => 'videos', 'posts_per_page' => 20, 'orderby' => 'date', 'order' => 'ASC' );
                    $loop = new WP_Query( $args );
                    while ( $loop->have_posts() ) : $loop->the_post();
//$args = array( 'post_type' => 'videos', 'posts_per_page' => 20, 'orderby' => 'date', 'order' => 'ASC' );
$ytubeID = get_post_meta($post->ID, '_youtubeID', true);
$vimID = get_post_meta($post->ID, '_vimeoID', true);
if ($ytubeID || $vimID){
if ($ytubeID){

echo '<iframe title="YouTube video player" class="youtube-player" type="text/html" src="http://www.youtube.com/embed/'.$ytubeID.'"  allowfullscreen="true" frameborder="0" width="640" height="390">';

echo '</iframe>';
} elseif ($vimID){
echo '<br />';
echo '<iframe src="http://player.vimeo.com/video/'.$vimID.'" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
}//end if yutbeID or vimIDthe_excerpt(); //excerpt added for information
}

endwhile;
                    wp_reset_query();

?>
1
Im sorry @brasofilo I really dont know.Neelam Khan
Well, the answer is no, don't multi-post the same Question in 2 sites.brasofilo

1 Answers

1
votes

SHOW VIDEO ON THE BASIS OF CURRENT'S POST CATEGORY

<?php

    $args = array( 'post_type' => 'videos', 'posts_per_page' => 20, 'orderby' => 'date', 'order' => 'ASC' );

    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();

        //$args = array( 'post_type' => 'videos', 'posts_per_page' => 20, 'orderby' => 'date', 'order' => 'ASC' );
        $ytubeID = get_post_meta($post->ID, '_youtubeID', true);
        $vimID = get_post_meta($post->ID, '_vimeoID', true);

        $videos_categories = array();           // ARRAY CONTAINING ALL CATEGORY ID ASSIGNED TO THIS POST
        $videos_cat_id = get_the_category(); // GET ALL CATEGORIES OBJECT ASIGNED TO CURRENT POST

        foreach($videos_cat_id as $videos_catid){
            $videos_categories[] = $catid->cat_ID;
        }
        $videos_cat_to_check = get_cat_ID( $videos_cat_name  ) // EXAMPLE get_cat_ID( 'music'  ) 



        if ($ytubeID || $vimID){
            if ($ytubeID && in_array($videos_cat_to_check,$videos_categories)){ // CHECK IF CURRENT POST HAS CATEGORY MUSIC 

                echo '<iframe title="YouTube video player" class="youtube-player" type="text/html" src="http://www.youtube.com/embed/'.$ytubeID.'"  allowfullscreen="true" frameborder="0" width="640" height="390">';

                echo '</iframe>';
                } elseif ($vimID){
                echo '<br />';
                echo '<iframe src="http://player.vimeo.com/video/'.$vimID.'" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
                }//end if yutbeID or vimIDthe_excerpt(); //excerpt added for information
        }

    endwhile;
    wp_reset_query();

    ?>