• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Display post meta in 2 places (AgentPress 2.0)

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

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

This topic is: resolved

Tagged: .post-info, action hook, filter hook, functions, hooks, post meta, show post meta twice

  • This topic has 1 reply, 1 voice, and was last updated 10 years, 7 months ago by asterbird.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • February 5, 2013 at 11:23 am #18240
    asterbird
    Member

    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)

    // 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;
     }
    

    When I add:

    // 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;
     }
    

    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/

    February 8, 2013 at 9:45 am #18936
    asterbird
    Member

    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:

    /**
    * 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;
    }
    

    Hope it helps someone else too!

  • Author
    Posts
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.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble