Last active
September 4, 2017 12:35
-
-
Save svenl77/ed6d648b4cf8529770af35ae01ebfd8a to your computer and use it in GitHub Desktop.
Hook Form Elements saved as Post Meta ( Custom Fields ) under the title of the listing or the excerpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Hook Post Meta ( Custom Fields ) under the title of the listing | |
add_action('buddyforms_the_loop_item_title_after', 'my_buddyforms_the_loop_item_last', 10, 1); | |
// Hook Post Meta ( Custom Fields ) under the excerpt of the listing | |
// This hook only exists in the the-loop.php template | |
add_action('buddyforms_the_loop_item_excerpt_after', 'my_buddyforms_the_loop_item_last', 10, 1); | |
// Example function for the title and the excerpt after hooks | |
function my_buddyforms_the_loop_item_last($post_id){ | |
// Get the post meta by the form element slug | |
// Change the "SLUG" to the form element slug of the foem element you like to get the value from. | |
$value = get_post_meta( $post_id, 'SLUG', true); | |
// Check if the post meta exist and have a value. Only add the value if the variable $value is not empty | |
if( ! empty( $value ) ){ | |
echo '<p>' . $value . '</p>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment