WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Custom Field Template] using PHP in the_content() hook (3 posts)

  1. Mark
    Member
    Posted 5 years ago #

    This experimental the_content() hook is fabulous. Saves one from adding shortcodes into posts. However, I'd like to use PHP code in it to set the field to not display when empty (using this type of code).

    Right now when I check 'Use PHP' it throws errors like unexpected $end and so on. Playing with the PHP code doesn't seem to solve the problem.

    http://wordpress.org/extend/plugins/custom-field-template/

  2. Hiroaki Miyashita
    Member
    Posted 4 years ago #

    You can not separate the php codes if you have conditional statements like if. So this does NOT work:

    <?php if ( get_post_meta($post->ID, 'your_key_name', true) ) { ?>
    <?php echo get_post_meta($post->ID, "your_key_name", $single = true); ?>
    <?php } ?>

    This does work:

    <?php if ( get_post_meta($post->ID, 'your_key_name', true) ) {
    echo get_post_meta($post->ID, "your_key_name", $single = true);
    } ?>

    Please try it out.

  3. egordin
    Member
    Posted 4 years ago #

    Hiroaki,

    This code you provided does not seem to work neither in the CFT shortcodes formatting box nor the Autohook content box (I did replace your_key_name with both [my_key_name] and my_key_name.

    Can you clarify how to get this to work, or add the ability to ignore/hide empty custom fields?

Topic Closed

This topic has been closed to new replies.

About this Topic