• Hi,

    Im trying to get a thumbnail from a custom post type to display on a particular page/post etc. depending on the conditional tag that has been included in the custom field of that post.
    For example is_home() is_page(22) etc.

    I can get the thumbnail to appear on all the pages but when I use an if statement with get_post_meta conditional tag it doesnt work

    <?php if ( get_post_meta($post->ID, 'ad-location', true) ) {  ?>
    global $post;
    $args = array( 'numberposts' => 1, 'post_type' => 'advert' );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post);
    	the_post_thumbnail('header1-ad');
    endforeach;
    <?php } ?>

    Ive been using simple ad manager but its overboard for what I need

Viewing 2 replies - 1 through 2 (of 2 total)
  • depending on the conditional tag that has been included in the custom field of that post.

    what is the content of the custom field?

    (your if statement is true if anything at all is in the custom field)

    it doesnt work

    what exactly does not work in which way?

    Thread Starter stemie

    (@stemie)

    This is what Im trying to achive, say I have a custom field with a value ‘is_home()’ for the key ‘ad-location’.

    I want the custom filed key to output its value as below:

    <?php if ( is_home() ) {  ?>
    global $post;
    $args = array( 'numberposts' => 1, 'post_type' => 'advert' );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post);
    	the_post_thumbnail('header1-ad');
    endforeach;
    <?php } ?>

    That is why I have written the code in my theme like this:

    <?php if ( get_post_meta($post->ID, 'ad-location', true) )

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Conditional tag in custom field’ is closed to new replies.