Last active
December 30, 2018 12:23
-
-
Save turtlepod/0642d19439de6b96da06342619ed705a to your computer and use it in GitHub Desktop.
Listify Snippet: Add Listing Category in Listing Card
This file contains 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 | |
/** | |
* Add Category List To Listing Data. | |
* | |
* @link https://gist.github.com/turtlepod/0642d19439de6b96da06342619ed705a | |
*/ | |
add_filter( 'listify_get_listing_to_array', function( $data, $listing ) { | |
// Default value for categories. | |
$categories = array(); | |
// Get post terms for listing categories. | |
$terms = get_the_terms( $listing->get_object(), 'job_listing_category' ); | |
// Check if term exists. | |
if ( $terms && ! is_wp_error( $terms ) ) { | |
// Loop for each terms. | |
foreach( $terms as $term ) { | |
// Add only the name of the term in the list. | |
$categories[] = $term->name; | |
} | |
} | |
// Add in listing data, format it as comma separated. | |
$data['categories'] = implode( ', ', $categories ); | |
// Return modified list of data. | |
return $data; | |
}, 10, 2 ); | |
/** | |
* Display the category data in listing card. | |
* | |
* @link https://gist.github.com/turtlepod/0642d19439de6b96da06342619ed705a | |
*/ | |
add_action( 'listify_content_job_listing_meta', function() { | |
// Check if available. | |
echo '<# if ( data.categories ) { #>'; | |
// Output inside a <div> | |
echo '<div class="my-listing-categories">{{{data.categories}}}</div>'; | |
// End check. | |
echo '<# } #>'; | |
} ); |
very good...
I wanted a Add Listing Category in Listing Card code to display the "company_website" link from "job_listing-url". click and send the user direct to external site. Can you create?
Hi! it's perfect to show the listing category, but if i also want to show the listing type of job, what code i have to write? Thanks and sorry for my poor english.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Facebook Group Post: https://www.facebook.com/groups/1035604846471813/permalink/1705707829461508/
(for discussion)