Community Forums › Forums › Archived Forums › Design Tips and Tricks › Display post meta in 2 places (AgentPress 2.0)
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 11 years, 11 months ago by asterbird.
-
AuthorPosts
-
February 5, 2013 at 11:23 am #18240asterbirdMember
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 #18936asterbirdMemberI 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!
-
AuthorPosts
- The topic ‘Display post meta in 2 places (AgentPress 2.0)’ is closed to new replies.