Hooks – Actions & Filters

Below is a list of some useful Actions and Filters that will allow you to customize your automotive listings.

The plugin contains many more hooks, so if you are a developer then by all means dig into the source code and take a look.

See this WordPress Codex article for more information on using Actions and Filters.

Add a custom field to the listings

The snippet below will add a new text field to the ‘Details’ metabox within the Edit Listing screen.

It will be added below the ‘Condition’ textfield. You could change the index from 1 to 6 and this would insert the field between the ‘Price’ and ‘Condition’.

add_filter( 'auto_listings_metabox_details', function ( $fields ) {
    $prefix = '_al_listing_';
    $fields[5] = array(
        'name' => __( 'Custom Field', 'auto-listings' ),
        'desc' => __( 'A custom description', 'auto-listings' ),
        'id' => $prefix . 'custom_field',
        'type' => 'text',
    );
    return $fields;
} );

To get the value of this custom field it is simply a matter of using get_post_meta( get_the_ID(), '_al_listing_custom_field', true) somewhere within the listing template.

To add the custom field in a different metabox, you can use one of the following filters:

auto_listings_metabox_images
auto_listings_metabox_select_vehicle
auto_listings_metabox_specs
auto_listings_metabox_address
auto_listings_metabox_settings

Modify localized script data

Returns an array of localized data for use in JavaScript.

apply_filters( 'auto_listings_localized_script', 'your_custom_filter_function', 10, 1 );

This filter allows you to modify the localized script data that is used for various Javascript functions such as maps and slideshow galleries on single listings.

You could use this filter to set different options on individual listings such as a different map height or slide duration.

Change the default theme template path

Returns a string.

apply_filters( 'auto_listings_template_path', 'your_custom_filter_function', 10, 1 );

With this filter, you can set the Template path to be used in your theme folder.

Any correctly named templates in this folder will override the default plugin templates.

The path is set as ‘listings/’ by default. You could change this template path to ‘my-templates/’ as an example.

Change default blank image

Returns a string.

apply_filters( 'auto_listings_default_no_image', 'your_custom_filter_function', 10, 1 );

Use this filter to change the default blank image on listings.

An example of this in use:

apply_filters( 'auto_listings_default_no_image', function ( $url ) {
    $url = 'http://yourwebsite.com/the-url-to-the-image/image.jpg';
    return $url;
} );

Newsletter

Subscribe to get the best deals and news from us. No spam, ever!