Skip to content

Instantly share code, notes, and snippets.

@turtlepod

turtlepod/functions.php

Last active Dec 30, 2018
Embed
What would you like to do?
Listify Snippet: Add Listing Category in Listing Card
<?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 '<# } #>';
} );
@turtlepod

This comment has been minimized.

Copy link
Owner Author

@turtlepod turtlepod commented Nov 13, 2017

@Adrianoweb1

This comment has been minimized.

Copy link

@Adrianoweb1 Adrianoweb1 commented May 19, 2018

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?

@jordiroscamps

This comment has been minimized.

Copy link

@jordiroscamps jordiroscamps commented Dec 30, 2018

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