Forums

Custom Field cascading system (4 posts)

  1. Norke
    Member
    Posted 11 months ago #

    Hi WordPressers :)

    I have a custom field property 'BannerImage' for my pages.

    When it's not filled in, it should find the 'BannerImage' of its parent. Is this hard to do?

    Thx for keeping me posted :)

    Kind regards,
    Yannick

  2. esmi
    Theme Diva & Forum Moderator
    Posted 11 months ago #

    In theory, yes.

    if( !get_post_meta($post_id, 'BannerImage', true) ) $custom_field = get_post_meta($post->parent, 'BannerImage', true);
    else $custom_field = get_post_meta($post_id, 'BannerImage', true);
  3. Norke
    Member
    Posted 11 months ago #

    Oh esmi,

    Thank you!

    This is what I ended up with:

    if(!get_post_meta($post->ID, 'BannerImage', true)) {
    		$banner_image = get_post_meta($post->post_parent, 'BannerImage', true);
    	} else {
    		$banner_image = get_post_meta($post->ID, 'BannerImage', true);
    	}
    	echo '<img src="' . $banner_image . '" />';

    Thx again for the quick help!

  4. esmi
    Theme Diva & Forum Moderator
    Posted 11 months ago #

    Glad I could help - even if I did get $post->parent wrong (I should have checked first). :-)

Reply

You must log in to post.

About this Topic