Ready to get started?Download WordPress


[resolved] Child page custom field overriding partent custom fields (5 posts)

  1. vectyr
    Posted 1 year ago #

    Client wants to style each page of his site differently. Using this to display two custom fields.

    <?php $mymeta = get_post_meta($post->ID, 'background_image', true); if ($mymeta) {echo '<style type="text/css" media="screen">.background {background-image: url('.$mymeta.') !important;'; } ?>
    	<?php $mymeta = get_post_meta($post->ID, 'background_color', true); if ($mymeta) {echo 'background-color: #'.$mymeta.' !important;} </style>'; } ?>

    Problem is that I created a main page that displays child pages and on the main page, I think the first child custom fields are overriding the parent page's custom fields.

    Parent Page: http://sugareffect.com/dev/works/
    1st Child Page: http://sugareffect.com/dev/works/sugar-effect-into-sequence/

    Is there a way to display the custom fields for the current page only while ignoring the custom fields from the child pages?

  2. paulwpxp
    Font hero
    Posted 1 year ago #

    Are you sure there is really a parent's custom field ?

    Is your parent page a real page or archive ?

  3. vectyr
    Posted 1 year ago #

    You know, you're right, these ARE archive pages. I'm looking at the blog and post pages and particularly a custom post type archive page.

  4. vectyr
    Posted 1 year ago #

    Still need a solution though, any ideas?

  5. paulwpxp
    Font hero
    Posted 1 year ago #

    Conditionally fire your CSS from meta, like for example

    if ( 'works' == get_post_type() ) { <-your css from meta goes here-> }


    if ( !is_post_type_archive() ) { <-your css from meta goes here-> }

Topic Closed

This topic has been closed to new replies.

About this Topic