Created
February 7, 2018 23:05
-
-
Save CapWebSolutions/acec182a7337ffe722c1d2f017833501 to your computer and use it in GitHub Desktop.
Create custom-post-meta shortcode to insert custom taxonomy into genesis post_meta
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
| /** A custom shortcode to fetch terms of a custom taxomomy for any post **/ | |
| add_shortcode( 'prefix-custom-post-meta', 'prefix_custom_post_meta' ); | |
| function prefix_custom_post_meta( $atts ) { | |
| $defaults = array( | |
| 'prepend' => 'Listed Under: ', // Text to be added before the terms output. | |
| 'append' => '', // Text to be added after the terms ouptut. | |
| 'separator' => '· ', // Separator used to separate multiple terms. | |
| 'taxonomy' => '', // Taxonomy name to fetch the terms from. Replace to set a default. | |
| ); | |
| $atts = shortcode_atts( $defaults, $atts, 'wsm-custom-post-meta' ); | |
| // using get_the_term_list() to retrieve all the associated taxonomy terms for a taxonomy | |
| $prefix_tax = get_the_term_list( $post->ID, $atts['taxonomy'], '', trim( $atts['separator'] ) . ' ', '' ); | |
| $output = '<span class="entry-categories wsm-categories">' . $atts['prepend'] . $wsm_tax . $atts['append'] . '</span>'; | |
| // Allow a filter to change the default output and the shortcode attributes/arguments | |
| return apply_filters( 'prefix_custom_post_meta', $output, $atts ); | |
| } | |
| // Customize the post meta function using above shortcode | |
| add_filter( 'genesis_post_meta', 'post_meta_filter' ); | |
| function post_meta_filter( $post_meta ) { | |
| if ( ! is_singular( array( 'post', 'job_posting' ) ) ) return; | |
| if ( is_singular( array( 'post' ) ) ) { | |
| $post_meta = '[post_categories sep=", " before="Job Category: "] [post_tags sep=", " before="Employer: "] '; | |
| } else { | |
| // here it must be a job_posting | |
| $post_meta = '[prefix-custom-post-meta taxonomy="employment_type" prepend="Employment Type: "] [post_categories sep=", " before="Job Category: "] [post_tags sep=", " before="Employer: "] '; | |
| } | |
| return $post_meta; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment