Display post meta in 2 places (AgentPress 2.0)

Community Forums Forums Design Tips and Tricks Display post meta in 2 places (AgentPress 2.0)

This topic is: resolved

This topic contains 1 reply, has 1 voice, and was last updated by  asterbird 1 year, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18240

    asterbird
    Participant
    Post count: 101

    Hello!

    How can I show the post meta twice for my AgentPress listings? I would like to show some meta below the post title and some meta in the sidebar of the same page.

    I registered 3 taxonomies in the AgentPress Listings plugin: price, beds, baths. I would like to display the beds and baths under the post title, and the price in the sidebar.

    This works for under the title: (code is in my theme functions.php)

    [php]
    // Move post meta to below title
    remove_action( ‘genesis_after_post_content’, ‘genesis_post_meta’ );
    add_action( ‘genesis_after_post_title’, ‘genesis_post_meta’ );

    // Customize the post meta function
    add_filter( ‘genesis_post_meta’, ‘custom_post_meta’ );
    function custom_post_meta($post_meta) {
    $post_meta = ‘[post_terms taxonomy="bathrooms"] [post_terms taxonomy="bedrooms"]‘;
    return $post_meta;
    }
    [/php]

    When I add:

    [php]
    // Move post meta to sidebar
    add_action( ‘genesis_before_sidebar_widget_area’, ‘genesis_post_meta’ );

    // Customize the post meta function
    add_filter( ‘genesis_post_meta’, ‘custom_post_meta_2′ );
    function custom_post_meta_2($custom_post_meta) {
    $custom_post_meta = ‘[post_terms taxonomy="price"]‘;
    return $custom_post_meta;
    }
    [/php]

    it displays only the price in both places.

    I’m sure it’s because I don’t know enough about php and action/filter hooks. Please help! I’m at a loss as to what to do.

    Website: http://hr.sarah-moyer.com/listings/153c-n-kent-street/

    #18936

    asterbird
    Participant
    Post count: 101

    I found a way to do this, but it’s probably a poor way to do it. I use both genesis_post_meta and genesis_post_info to display post meta in two places.

    I moved the genesis_post_meta to the sidebar which displays terms from the taxonomy Attractions. And I used the genesis_post_info to display terms from the taxonomies Price, Beds, and Baths.

    Here’s what works for me finally:

    [php]
    /**
    * Use the post info function to display post meta instead
    */
    add_filter( ‘genesis_post_info’, ‘sarah_post_meta’ );
    function sarah_post_meta($post_info) {
    $post_info = ‘[post_terms before="" taxonomy="properties"][post_terms before=" | " taxonomy="price"][post_terms before=" | " taxonomy="bedrooms"][post_terms before=" | " taxonomy="bathrooms"]‘;
    return $post_info;
    }
    /**
    * Move the post meta function to sidebar
    */
    remove_action( ‘genesis_after_post_content’, ‘genesis_post_meta’ );
    add_action( ‘genesis_before_sidebar_widget_area’, ‘genesis_post_meta’ );
    /**
    * Modify the post meta function to display attractions taxonomy meta only
    */
    add_filter( ‘genesis_post_meta’, ‘sarah_attractions_meta’ );
    function sarah_attractions_meta( ) {

    $terms = get_the_terms( $post->ID, ‘attractions’ );

    if ( $terms && ! is_wp_error( $terms ) ) :

    $attraction_terms = array();

    echo "<h4>Attractions Near " . get_the_title() . "</h4>";

    foreach ( $terms as $term ) {
    echo ‘<li><a href="’ . get_term_link($term->slug, ‘attractions’) . ‘">’ . $term->name . ‘</a></li>’;
    echo ‘<li>’ . $term->description . ‘</li>’;
    }

    $attractions = join( ", ", $attraction_terms );
    endif;
    }
    [/php]

    Hope it helps someone else too!

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

The topic ‘Display post meta in 2 places (AgentPress 2.0)’ is closed to new replies.