Hooks & Filters
Community Listings provides a comprehensive set of hooks and filters to let developers extend and customize the plugin without modifying its source code.
Filters
cl_default_image_{ category_slug }
Override the default fallback image for a specific category. The category slug is appended to the filter name (e.g., cl_default_image_food-dining).
add_filter( 'cl_default_image_food-dining', function( $image_url ) {
return get_template_directory_uri() . '/images/custom-food.svg';
} ); | Parameter | Type | Description |
|---|---|---|
$image_url | string | The default fallback image URL for this category |
cl_listing_types
Modify the registered listing types. Use this to add custom listing types beyond "visual" and "structured".
add_filter( 'cl_listing_types', function( $types ) {
$types['premium'] = array(
'label' => __( 'Premium Listing', 'my-theme' ),
'template' => 'listing-premium.php',
);
return $types;
} ); cl_categories
Modify the default category list that is created on activation.
add_filter( 'cl_categories', function( $categories ) {
$categories[] = array(
'name' => __( 'Education', 'my-theme' ),
'slug' => 'education',
'type' => 'structured',
);
return $categories;
} ); cl_listing_query_args
Modify the WP_Query arguments used to fetch listings in shortcodes and blocks.
add_filter( 'cl_listing_query_args', function( $args, $atts ) {
// Only show listings from the current month
$args['date_query'] = array(
array(
'after' => '1 month ago',
'inclusive' => true,
),
);
return $args;
}, 10, 2 ); | Parameter | Type | Description |
|---|---|---|
$args | array | WP_Query arguments array |
$atts | array | Shortcode attributes that were passed |
cl_listing_card_html
Filter the final HTML output for an individual listing card (visual listings).
add_filter( 'cl_listing_card_html', function( $html, $post_id, $type ) {
// Add a badge for featured listings
if ( get_post_meta( $post_id, '_cl_featured', true ) ) {
$badge = '<span class="cl-badge">Featured</span>';
$html = str_replace( '<div class="cl-listing-card">',
'<div class="cl-listing-card">' . $badge, $html );
}
return $html;
}, 10, 3 ); | Parameter | Type | Description |
|---|---|---|
$html | string | The rendered HTML for the listing card |
$post_id | int | The listing post ID |
$type | string | The listing type (visual or structured) |
cl_submit_form_fields
Add, remove, or modify fields in the frontend submission form.
add_filter( 'cl_submit_form_fields', function( $fields, $category ) {
// Add a custom "Hours of Operation" field
$fields['hours'] = array(
'label' => __( 'Hours of Operation', 'my-theme' ),
'type' => 'textarea',
'required' => false,
'meta_key' => '_cl_hours',
);
return $fields;
}, 10, 2 ); | Parameter | Type | Description |
|---|---|---|
$fields | array | Associative array of form fields |
$category | string | The currently selected category slug |
cl_notification_email
Customize the admin notification email sent when a new listing is submitted.
add_filter( 'cl_notification_email', function( $email, $listing_id ) {
$email['subject'] = 'New Listing: ' . get_the_title( $listing_id );
$email['headers'][] = 'CC: manager@example.com';
return $email;
}, 10, 2 ); | Parameter | Type | Description |
|---|---|---|
$email | array | Array with keys: to, subject, body, headers |
$listing_id | int | The newly created listing post ID |
cl_allowed_mime_types
Control which file types are allowed for image uploads in the frontend submission form.
add_filter( 'cl_allowed_mime_types', function( $types ) {
$types['webp'] = 'image/webp';
return $types;
} ); Actions
cl_before_listings
Fires before the listings grid is rendered. Useful for adding custom markup, search forms, or filter UI.
add_action( 'cl_before_listings', function( $atts ) {
echo '<div class="my-custom-filter-bar">';
// Custom filter UI
echo '</div>';
} ); | Parameter | Type | Description |
|---|---|---|
$atts | array | The shortcode attributes |
cl_after_listings
Fires after the listings grid is rendered. Useful for adding pagination, CTAs, or supplementary content.
add_action( 'cl_after_listings', function( $atts ) {
echo '<p><a href="/submit/">Add your listing</a></p>';
} ); cl_listing_submitted
Fires after a new listing is successfully submitted via the frontend form. Useful for integrations, analytics, or additional notifications.
add_action( 'cl_listing_submitted', function( $listing_id, $user_id ) {
// Log submission to external service
wp_remote_post( 'https://api.example.com/webhook', array(
'body' => array(
'listing_id' => $listing_id,
'title' => get_the_title( $listing_id ),
),
) );
}, 10, 2 ); | Parameter | Type | Description |
|---|---|---|
$listing_id | int | The new listing post ID |
$user_id | int | The ID of the user who submitted the listing |
cl_listing_approved
Fires when an admin approves (publishes) a pending listing. Useful for sending confirmation emails to the submitter.
add_action( 'cl_listing_approved', function( $listing_id ) {
$user_id = get_post_meta( $listing_id, '_cl_submitted_by', true );
$user = get_user_by( 'id', $user_id );
if ( $user ) {
wp_mail( $user->user_email, 'Your listing has been approved!',
'Your listing "' . get_the_title( $listing_id ) . '" is now live.' );
}
} ); cl_before_submit_form
Fires before the submission form is rendered. Use for adding instructions or notices.
cl_after_submit_form
Fires after the submission form is rendered.
Quick Reference Table
| Hook Name | Type | Description |
|---|---|---|
cl_default_image_{slug} | Filter | Override fallback image per category |
cl_listing_types | Filter | Modify registered listing types |
cl_categories | Filter | Modify default category list |
cl_listing_query_args | Filter | Modify listing query arguments |
cl_listing_card_html | Filter | Filter individual listing HTML output |
cl_submit_form_fields | Filter | Modify frontend form fields |
cl_notification_email | Filter | Customize admin notification email |
cl_allowed_mime_types | Filter | Control allowed upload file types |
cl_before_listings | Action | Before listings grid output |
cl_after_listings | Action | After listings grid output |
cl_listing_submitted | Action | After frontend submission |
cl_listing_approved | Action | After admin approves a listing |
cl_before_submit_form | Action | Before submission form render |
cl_after_submit_form | Action | After submission form render |