• Resolved redsundesign

    (@redsundesign)


    I have a function in functions.php which embeds a video url from a text-only custom field in the WP admin area (which contains a YouTube video URL).

    I want the same video to show on all pages so have added the post_id after the custom field name. The video shows fine on the home page (post_id=2) but not on other pages.

    Could someone point out where I’m going wrong? Many thanks in advance…

    function show_vid() {
    	if (get_field("video_url")):
    		$vid_url = get_field("video_url",2);
    		global $wp_embed;
    		$post_embed = $wp_embed->run_shortcode('[embed]'.$vid_url.'[/embed]');
    		echo '<div class="vid-area">'.$post_embed.'</div>';
    	endif;
    }

    https://wordpress.org/plugins/advanced-custom-fields/

Viewing 1 replies (of 1 total)
  • Thread Starter redsundesign

    (@redsundesign)

    Must be having a bad day. The custom field is set to only show on the home page in the admin area so the lack of post_id in the “if” statement was causing the video to not show on other pages – doh. Apologies…

    function show_vid() {
    	if (get_field("video_url",2)):
    		$vid_url = get_field("video_url",2);
    		global $wp_embed;
    		$post_embed = $wp_embed->run_shortcode('[embed]'.$vid_url.'[/embed]');
    		echo '<div class="vid-area">'.$post_embed.'</div>';
    	endif;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘post_id is being ignored’ is closed to new replies.