• Resolved hammeri1

    (@hammeri1)


    Hi Greg,

    I read a post you responded to a couple of years back on this but haven’t been able to make the necessary edits you suggest to add the custom field I want next to Title in the Advert Listing. The post link is https://ww.wp.xz.cn/support/topic/how-to-include-custom-fields-on-the-add-lists-adverts_list/ and you recommend modifying the list-item.php file in WP Adverts / Templates.

    I want to add my custom field ‘bedroom_count’ to appear next to Title in each listing. I’ve tried editing the line:

    <span title=”<?php echo esc_attr( get_the_title() ) ?>” class=”advert-link”>

    with the following code (and various combinations of)

    <?php the_title(); echo ‘ ‘ . get_post_meta( get_the_ID(), ‘bedroom_count’, true ) ?>

    but no luck.

    Can you advise where I need to make the necessary edits? Also should I modify list-item.php directly or in a plug in?

    Many thanks,

    Richard.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    You can add in your theme functions.php file the code below (or even better create a new WP plugin and paste the code there).

    
    add_action( "adverts_list_after_title", "bedrooms_in_the_title" );
    function bedrooms_in_the_title( $post_id ) {
        echo sprintf( "Bedrooms: %d", get_post_meta( $post_id, 'bedroom_count', true ) );
    }
    
    Thread Starter hammeri1

    (@hammeri1)

    Fantastic! Works a treat.

    Many thanks.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Adding custom fields to Advert Listing’ is closed to new replies.