Below, you’ll find a detailed guide on how to add the Auto Listings Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Auto Listings Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Auto Listings Plugin and the shortcodes it provides:
"Auto Listings – Car Listings & Car Dealership Plugin for WordPress is a comprehensive tool for managing automotive listings. Ideal for car dealerships and auto traders, this plugin simplifies the process of listing and selling vehicles on your WordPress site."
- [auto_listings_contact_form]
- [als_button]
- [als_total_listings]
- [als_selected]
- [als_toggle_wrapper]
- [als_keyword]
- [auto_listings_search]
- [auto_listings_listing]
- [auto_listings_listings]
- [mb_frontend_dashboard]
Auto Listings [auto_listings_contact_form] Shortcode
The ‘auto_listings_contact_form’ shortcode is utilized to create a contact form in the Auto Listings plugin. This form allows users to send inquiries directly from the listing page. This shortcode pulls in the site’s reCAPTCHA keys and the AJAX setting for the contact form. It then generates a Meta Box frontend form with these settings. The form includes a ‘Send Enquiry’ submit button.
Shortcode: [auto_listings_contact_form]
Parameters
Here is a list of all possible auto_listings_contact_form shortcode parameters and attributes:
id
– unique identifier of the contact formajax
– determines if the form submission will be asynchronoussubmit_button
– text displayed on the form’s submit buttonrecaptcha_key
– site key for Google reCAPTCHA validationrecaptcha_secret
– secret key for Google reCAPTCHA validation
Examples and Usage
Basic example – A standard implementation of the ‘auto_listings_contact_form’ shortcode. This will display the contact form with default settings as defined in the plugin’s settings.
[auto_listings_contact_form]
Advanced examples
Customizing the form’s submit button text and enabling AJAX. This will change the label of the form’s submit button to ‘Submit Your Enquiry’ and enable AJAX form submission, which can improve user experience by allowing the form to be submitted without a page reload.
[auto_listings_contact_form ajax="true" submit_button="Submit Your Enquiry"]
Implementing reCAPTCHA for spam protection. This example includes the site key and secret key for reCAPTCHA, which adds a layer of spam protection to the form. Replace ‘your_site_key’ and ‘your_secret_key’ with your actual reCAPTCHA keys.
[auto_listings_contact_form recaptcha_key="your_site_key" recaptcha_secret="your_secret_key"]
Combining all parameters for a fully customized form. This example demonstrates how to use all available parameters to create a fully customized contact form. It includes customized submit button text, AJAX form submission, and reCAPTCHA spam protection.
[auto_listings_contact_form ajax="true" submit_button="Submit Your Enquiry" recaptcha_key="your_site_key" recaptcha_secret="your_secret_key"]
PHP Function Code
In case you have difficulties debugging what causing issues with [auto_listings_contact_form]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'auto_listings_contact_form', [ $this, 'contact_form_shortcode' ] );
Shortcode PHP function:
function contact_form_shortcode() {
$submit_button = __( 'Send Enquiry', 'auto-listings' );
$recaptcha_site_key = auto_listings_option( 'captcha_site_key' );
$recaptcha_secret = auto_listings_option( 'captcha_secret_key' );
$is_ajax = auto_listings_option( 'contact_form_ajax' ) ? 'true' : 'false';
$shortcode = sprintf( '[mb_frontend_form id="auto_listings_contact_form" ajax="%s" submit_button="%s" recaptcha_key="%s" recaptcha_secret="%s"]', $is_ajax, $submit_button, $recaptcha_site_key, $recaptcha_secret );
return do_shortcode( $shortcode );
}
Code file location:
auto-listings/auto-listings/src/Enquiry/ContactForm.php
Auto Listings [als_button] Shortcode
The Auto-Listings shortcode, ‘als_button’, is designed to render a button on the webpage. It accepts two attributes: ‘type’ and ‘label’. The ‘type’ attribute determines whether the button is a ‘submit’ button or a regular ‘button’. The ‘label’ attribute sets the text displayed on the button. By default, it shows ‘Submit’.
Shortcode: [als_button]
Parameters
Here is a list of all possible als_button shortcode parameters and attributes:
type
– Determines the button type, default is ‘submit’label
– Sets the button text, default is ‘Submit’
Examples and Usage
Basic example – The shortcode below creates a simple button with the label ‘Submit’.
[als_button /]
Advanced examples
Creating a button of type ‘button’ rather than ‘submit’, with a custom label ‘Click Me’.
[als_button type="button" label="Click Me" /]
Creating a ‘submit’ type button, but with a different label ‘Send Now’.
[als_button type="submit" label="Send Now" /]
These examples demonstrate the flexibility of the ‘als_button’ shortcode. You can control the button type and label text by passing different parameters to the shortcode. This allows you to create buttons that are tailored to your specific needs.
PHP Function Code
In case you have difficulties debugging what causing issues with [als_button]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'als_button', array( $this, 'render' ) );
Shortcode PHP function:
function render( $atts ) {
$atts = shortcode_atts(
array(
'type' => 'submit',
'label' => __( 'Submit', 'auto-listings' ),
),
$atts
);
$type = $atts['type'] === 'submit' ? 'submit' : 'button';
$output = sprintf( '<button class="als-%s" type="%s">%s</button>', esc_attr( $atts['type'] ), $type, esc_html( $atts['label'] ), 'auto-listings' );
return $output;
}
Code file location:
auto-listings/auto-listings/src/SearchForm/Shortcode/Button.php
Auto Listings [als_total_listings] Shortcode
The ‘als_total_listings’ shortcode from Auto Listings plugin retrieves and displays the total number of vehicle listings available. This shortcode calls the ‘render_total’ function, which uses the ‘auto_listings_search_get_vehicle_data()’ function to fetch the total count of vehicle listings.
Shortcode: [als_total_listings]
Examples and Usage
Basic example – The shortcode below will display the total number of auto listings available on your website. It is a simple and effective way to let your users know how many vehicle listings they can browse through.
[als_total_listings /]
Advanced examples
While the ‘als_total_listings’ shortcode does not inherently support additional parameters, you can customize its output by modifying the ‘render_total’ function in your theme’s functions.php file or a custom plugin. Here is an example of how you might modify the function to accept a ‘type’ parameter, which would allow you to display the total number of listings for a specific vehicle type.
add_shortcode( 'als_total_listings', 'render_total' );
function render_total($atts) {
$atts = shortcode_atts(
array(
'type' => 'all',
), $atts, 'als_total_listings' );
if ($atts['type'] == 'all') {
return auto_listings_search_get_vehicle_data()['total'];
} else {
return auto_listings_search_get_vehicle_data($atts['type'])['total'];
}
}
With the above modification, you can now use the ‘als_total_listings’ shortcode with a ‘type’ parameter to display the total number of listings for a specific vehicle type. For example, the following shortcode would display the total number of ‘SUV’ listings:
[als_total_listings type="SUV" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [als_total_listings]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'als_total_listings', array( $this, 'render_total' ) );
Shortcode PHP function:
function render_total() {
return auto_listings_search_get_vehicle_data()['total'];
}
Code file location:
auto-listings/auto-listings/src/SearchForm/Shortcode/Extras.php
Auto Listings [als_selected] Shortcode
The Auto-Listings shortcode, ‘als_selected’, is used to display a specific section on a webpage. It does this by rendering a div with the class “als-selected”.
Shortcode: [als_selected]
Examples and Usage
Basic example – Utilize the shortcode to render a div with a class of “als-selected”.
[als_selected /]
Advanced examples
Expanding the shortcode to accept parameters, we can customize the class and content of the div. Here’s how we can modify the PHP function:
function render_selected( $atts ) {
$atts = shortcode_atts(
array(
'class' => 'als-selected',
'content' => '',
),
$atts,
'als_selected'
);
return '' . esc_html( $atts['content'] ) . '';
}
add_shortcode( 'als_selected', 'render_selected' );
Now, we can use the shortcode with different parameters:
Example 1: Using the shortcode to display a div with a custom class.
[als_selected class="custom-class" /]
Example 2: Using the shortcode to display a div with custom content.
[als_selected content="This is custom content" /]
Example 3: Using the shortcode to display a div with both a custom class and custom content.
[als_selected class="custom-class" content="This is custom content" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [als_selected]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'als_selected', array( $this, 'render_selected' ) );
Shortcode PHP function:
function render_selected() {
return '<div class="als-selected"></div>';
}
Code file location:
auto-listings/auto-listings/src/SearchForm/Shortcode/Extras.php
Auto Listings [als_toggle_wrapper] Shortcode
Auto-Listings shortcode is a key tool in WordPress development. It enables the creation of a toggle wrapper around content. This shortcode’s function is to render a toggle wrapper. It takes attributes and content, defaulting the label to ‘Advanced Search’. The returned content is enclosed in a ‘div’ element with class ‘als-toggle-wrapper’.
Shortcode: [als_toggle_wrapper]
Parameters
Here is a list of all possible als_toggle_wrapper shortcode parameters and attributes:
label
– sets the text for the toggle wrapper’s label
Examples and Usage
Basic example – Showcases the implementation of the ‘als_toggle_wrapper’ shortcode without any additional parameters. In this scenario, the default label ‘Advanced Search’ will be used.
[als_toggle_wrapper][/als_toggle_wrapper]
For advanced examples:
Advanced example – Illustrates the usage of the ‘als_toggle_wrapper’ shortcode with a custom label. By specifying the ‘label’ parameter, we can customize the text that appears in the toggle wrapper.
[als_toggle_wrapper label="Custom Label"][/als_toggle_wrapper]
Another advanced example would be to nest other shortcodes inside the ‘als_toggle_wrapper’. Here, we are inserting a hypothetical ‘search_form’ shortcode inside the ‘als_toggle_wrapper’ shortcode. This allows us to encapsulate additional functionality within the toggle wrapper.
[als_toggle_wrapper label="Custom Label"][search_form][/als_toggle_wrapper]
PHP Function Code
In case you have difficulties debugging what causing issues with [als_toggle_wrapper]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'als_toggle_wrapper', array( $this, 'render_toggle_wrapper' ) );
Shortcode PHP function:
function render_toggle_wrapper( $atts, $content = null ) {
$atts = shortcode_atts(
array(
'label' => __( 'Advanced Search', 'auto-listings' ),
),
$atts
);
return '<div class="als-toggle-wrapper">' . do_shortcode( $content ) . '</div>';
}
Code file location:
auto-listings/auto-listings/src/SearchForm/Shortcode/Extras.php
Auto Listings [als_keyword] Shortcode
The Auto-Listings shortcode ‘als_keyword’ renders a search field for location input. It generates a unique ID and allows customization of the label and placeholder text. Within the ‘als-field’ div, the label and input field are appended, creating a user-friendly search interface. The placeholder text can be set to guide user input, such as ‘Town, city or postcode’. Shortcode: [als_keyword]
Shortcode: [als_keyword]
Parameters
Here is a list of all possible als_keyword shortcode parameters and attributes:
label
– Defines the display label of the input field.placeholder
– Sets the placeholder text within the input field.
Examples and Usage
Basic example – An example of a shortcode that renders a search keyword field with the default label and placeholder.
[als_keyword /]
Advanced examples
Customizing the label and placeholder of the search keyword field.
[als_keyword label="Search" placeholder="Enter keyword" /]
Using the shortcode with a custom label but with the default placeholder.
[als_keyword label="Find Car" /]
Using the shortcode with a custom placeholder but with the default label.
[als_keyword placeholder="Enter car model" /]
These examples illustrate how you can use the ‘als_keyword’ shortcode to customize the search keyword field in your auto listings. The ‘label’ and ‘placeholder’ attributes allow you to modify the field’s label and placeholder text, respectively.
PHP Function Code
In case you have difficulties debugging what causing issues with [als_keyword]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'als_keyword', array( $this, 'render_search_keyword' ) );
Shortcode PHP function:
function render_search_keyword( $atts ) {
$id = uniqid();
$atts = shortcode_atts(
array(
'label' => __( 'Location', 'auto-listings' ),
'placeholder' => __( 'Town, city or postcode', 'auto-listings' ),
),
$atts
);
$label = $atts['label'] ? '<label class="als-field__label" for="' . esc_attr( $id ) . '">' . $atts['label'] . '</label>' : '';
$output = '<div class="als-field als-field--keyword ">';
$output .= sprintf( '%1s<input id="%2s" type="text" name="s" placeholder="%3s" />', $label, $id, $atts['placeholder'] );
$output .= '</div>';
return $output;
}
Code file location:
auto-listings/auto-listings/src/SearchForm/Shortcode/Extras.php
Auto Listings [auto_listings_search] Shortcode
The Auto Listings Search shortcode is a powerful tool that generates a customizable search form for car listings. It allows users to filter results based on conditions, price range, area, and specific car features. The shortcode also supports different styles and layouts, providing flexibility in its implementation.
Shortcode: [auto_listings_search]
Parameters
Here is a list of all possible auto_listings_search shortcode parameters and attributes:
area_placeholder
– Text to display in location search field.submit_btn
– Text for the search button.refine_text
– Text for the ‘More Refinements’ option.style
– Style number for the search form.layout
– Layout setting for the search form.exclude
– Fields to exclude from the search form.
Examples and Usage
Basic example – A simple usage of the auto_listings_search shortcode that will display the default search form.
[auto_listings_search]
Advanced examples
Customizing the placeholder text for the area search field, the text on the submit button, and the text on the ‘More Refinements’ button. This example also excludes the ‘condition’ and ‘prices’ fields from the search form.
[auto_listings_search area_placeholder="Enter Location" submit_btn="Search Cars" refine_text="Additional Options" exclude="condition, prices"]
Displaying a different style of search form by changing the ‘style’ attribute to ‘2’ and setting the layout to ‘standard’. This example also excludes the ‘year’, ‘make’, ‘model’, ‘body_type’, and ‘odometer’ fields from the search form.
[auto_listings_search style="2" layout="standard" exclude="year, make, model, body_type, odometer"]
These examples show how you can use the auto_listings_search shortcode to create a search form that fits your specific needs. By adjusting the attributes in the shortcode, you can control the appearance and functionality of the search form.
PHP Function Code
In case you have difficulties debugging what causing issues with [auto_listings_search]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'auto_listings_search', [ $this, 'search_form' ] );
Shortcode PHP function:
function search_form( $atts ) {
$s = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';
$atts = shortcode_atts(
[
'area_placeholder' => __( 'State, Zip, Town', 'auto-listings' ),
'submit_btn' => __( 'Find My Car', 'auto-listings' ),
'refine_text' => __( 'More Refinements', 'auto-listings' ),
'style' => '1',
'layout' => '',
'exclude' => [],
],
$atts
);
$exclude = ! empty( $atts['exclude'] ) ? array_map( 'trim', explode( ',', $atts['exclude'] ) ) : [];
ob_start();
?>
<form
id="auto-listings-search" class="auto-listings-search s-<?php echo esc_attr( $atts['style'] ); ?> <?php echo esc_attr( $atts['layout'] ); ?>" autocomplete="off"
action="<?php the_permalink( auto_listings_option( 'archives_page' ) ); ?>"
method="GET"
role="search">
<?php if ( 'standard' !== $atts['layout'] ) : ?>
<?php if ( ! in_array( 'condition', $exclude, true ) ) : ?>
<div class="row condition-wrap">
<?php echo $this->condition_field(); // wpcs xss: ok. ?>
</div>
<?php endif; ?>
<?php if ( ! in_array( 'prices', $exclude, true ) ) : ?>
<div class="row price-wrap">
<?php
if ( ! in_array( 'min_price', $exclude, true ) ) {
echo $this->min_price_field(); // wpcs xss: ok.
}
if ( ! in_array( 'max_price', $exclude, true ) ) {
echo $this->max_price_field(); // wpcs xss: ok.
}
?>
</div>
<?php endif; ?>
<?php if ( ! in_array( 'area', $exclude, true ) ) : ?>
<div class="row area-wrap">
<?php echo $this->within_field(); // wpcs xss: ok. ?>
<input class="field area" type="text" name="s" placeholder="<?php echo esc_attr( $atts['area_placeholder'] ); ?>" value="<?php echo esc_attr( $s ); ?>"/>
<button class="al-button" type="submit"><?php echo esc_html( $atts['submit_btn'] ); ?></button>
</div>
<?php else : ?>
<div class="row area-wrap">
<input type="hidden" name="s" value="<?php echo esc_attr( $s ); ?>"/>
<button class="al-button" type="submit"><?php echo esc_html( $atts['submit_btn'] ); ?></button>
</div>
<?php endif; ?>
<?php if ( ! in_array( 'refine', $exclude, true ) ) : ?>
<a class="refine"><?php echo esc_html( $atts['refine_text'] ); ?><i class="fa fa-angle-down"></i></a>
<div class="row extras-wrap">
<?php
if ( ! in_array( 'year', $exclude, true ) ) {
echo $this->year_field(); // wpcs xss: ok.
}
if ( ! in_array( 'make', $exclude, true ) ) {
echo $this->make_field(); // wpcs xss: ok.
}
if ( ! in_array( 'model', $exclude, true ) ) {
echo $this->model_field(); // wpcs xss: ok.
}
if ( ! in_array( 'body_type', $exclude, true ) ) {
echo $this->body_type_field(); // wpcs xss: ok.
}
if ( ! in_array( 'odometer', $exclude, true ) ) {
echo $this->odometer_field(); // wpcs xss: ok.
}
do_action( 'auto_listings_extra_search_fields', $exclude );
?>
</div>
<?php endif; ?>
<?php else : ?>
<?php
if ( ! in_array( 'condition', $exclude, true ) ) {
echo $this->condition_field(); // wpcs xss: ok.
}
if ( ! in_array( 'prices', $exclude, true ) ) {
if ( ! in_array( 'min_price', $exclude, true ) ) {
echo $this->min_price_field(); // wpcs xss: ok.
}
if ( ! in_array( 'max_price', $exclude, true ) ) {
echo $this->max_price_field(); // wpcs xss: ok.
}
}
if ( ! in_array( 'year', $exclude, true ) ) {
echo $this->year_field(); // wpcs xss: ok.
}
if ( ! in_array( 'make', $exclude, true ) ) {
echo $this->make_field(); // wpcs xss: ok.
}
if ( ! in_array( 'model', $exclude, true ) ) {
echo $this->model_field(); // wpcs xss: ok.
}
if ( ! in_array( 'body_type', $exclude, true ) ) {
echo $this->body_type_field(); // wpcs xss: ok.
}
if ( ! in_array( 'odometer', $exclude, true ) ) {
echo $this->odometer_field(); // wpcs xss: ok.
}
if ( ! in_array( 'area', $exclude, true ) ) :
echo $this->within_field(); // wpcs xss: ok.
?>
<input class="field area" type="text" name="s" placeholder="<?php echo esc_attr( $atts['area_placeholder'] ); ?>" value="<?php echo esc_attr( $s ); ?>">
<?php else : ?>
<input type="hidden" name="s" value="<?php echo esc_attr( $s ); ?>"/>
<?php endif; ?>
<button class="al-button" type="submit"><?php echo esc_html( $atts['submit_btn'] ); ?></button>
<?php endif; ?>
</form>
<?php
$output = ob_get_clean();
return apply_filters( 'auto_listings_search_form_output', $output, $atts );
}
Code file location:
auto-listings/auto-listings/src/SearchForm.php
Auto Listings [auto_listings_listing] Shortcode
The Auto Listings shortcode is a powerful tool that simplifies listing management. It fetches a specific auto listing based on the ID provided. If no listing is found, a custom message is displayed. The shortcode generates a single listing layout, ensuring a consistent look across your site.
Shortcode: [auto_listings_listing]
Parameters
Here is a list of all possible auto_listings_listing shortcode parameters and attributes:
id
– The unique identifier for the specific auto listing.no_results
– The text message to show when no listings are found.
Examples and Usage
Basic example – Display a single auto-listing by its ID
[auto_listings_listing id=123 /]
Here, the shortcode is used to display a specific auto-listing post on your website. The ‘id’ attribute corresponds to the post ID of the auto-listing you want to display.
Advanced examples
Display a single auto-listing with a custom ‘no results’ message.
[auto_listings_listing id=123 no_results="No auto-listing found." /]
In this example, the shortcode is used to display a specific auto-listing post. If the post with the given ‘id’ is not found, it will display a custom ‘no results’ message instead of the default one. This allows you to customize the message based on the context in which the shortcode is used.
It’s important to note that while the shortcode can accept multiple attributes, they must be separated by spaces. Also, the attribute values must be enclosed in quotes if they contain spaces.
PHP Function Code
In case you have difficulties debugging what causing issues with [auto_listings_listing]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'auto_listings_listing', [ $this, 'listing' ] );
Shortcode PHP function:
function listing( $atts ) {
if ( is_admin() ) {
return '';
}
$atts = shortcode_atts(
apply_filters( 'auto_listings_shortcode_listings_default_atts', [
'id' => 0,
'no_results' => __( 'Sorry, no listings were found.', 'auto-listings' ),
] ),
$atts
);
$args = [
'post_type' => 'auto-listing',
'posts_per_page' => 1,
'no_found_rows' => 1,
'post_status' => 'publish',
'p' => $atts['id'],
];
$query = new \WP_Query( apply_filters( 'auto_listings_shortcode_listing_query', $args, $atts ) );
if ( ! $query->have_posts() ) {
$this->loop_no_results( $atts );
}
ob_start();
?>
<div id="listing-<?php the_ID(); ?>" class="auto-listings-single">
<?php
while ( $query->have_posts() ) :
$query->the_post();
?>
<?php auto_listings_get_part( 'content-single-listing.php' ); ?>
<?php endwhile; // end of the loop. ?>
</div>
<?php
wp_reset_postdata();
return ob_get_clean();
}
Code file location:
auto-listings/auto-listings/src/Shortcodes.php
Auto Listings [auto_listings_listings] Shortcode
The Auto Listings shortcode is a powerful tool for displaying vehicle listings on your website. This shortcode fetches and displays vehicle listings in a customizable format. You can sort by date, seller, or ID, choose the number of listings to display, and select between a grid or compact view. If no listings match your criteria, a customizable “no results” message will show.
Shortcode: [auto_listings_listings]
Parameters
Here is a list of all possible auto_listings_listings shortcode parameters and attributes:
orderby
– Determines the sorting of listings, default is by date.order
– Sets the order of listings, ascending by default.number
– Controls the number of listings to show, default is 20.seller
– Filters listings by the seller’s ID.ids
– Shows specific listings by their IDs.compact
– Sets the display mode to compact if true.columns
– Specifies the number of columns, default is 3.view
– Sets the view mode, grid is the default.no_results
– Message displayed when no listings are found.
Examples and Usage
Basic example – Displaying a list of auto listings ordered by date in ascending order.
[auto_listings_listings orderby="date" order="asc"]
Advanced examples
Displaying a list of auto listings, limited to 10 listings per page, in a grid view with 4 columns.
[auto_listings_listings number="10" view="grid" columns="4"]
Displaying a list of specific auto listings by referencing their IDs. The IDs are separated by commas.
[auto_listings_listings ids="1,2,3,4,5"]
Displaying a list of auto listings from a specific seller. The seller is identified by their ID.
[auto_listings_listings seller="1"]
Displaying a list of auto listings in compact mode. This mode removes the ‘at a glance’ and ‘description’ sections from the listings.
[auto_listings_listings compact="true"]
Displaying a list of auto listings with a custom message when no results are found.
[auto_listings_listings no_results="No listings available at the moment."]
PHP Function Code
In case you have difficulties debugging what causing issues with [auto_listings_listings]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'auto_listings_listings', [ $this, 'listings' ] );
Shortcode PHP function:
function listings( $atts ) {
if ( is_admin() ) {
return '';
}
$atts = shortcode_atts(
apply_filters( 'auto_listings_shortcode_listings_default_atts', [
'orderby' => 'date',
'order' => 'asc',
'number' => '20',
'seller' => '', // id of the seller.
'ids' => '',
'compact' => '',
'columns' => '3',
'view' => 'grid',
'no_results' => __( 'Sorry, no listings were found.', 'auto-listings' ),
] ),
$atts
);
$query_args = [
'post_type' => 'auto-listing',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'orderby' => $atts['orderby'],
'order' => $atts['order'],
'posts_per_page' => $atts['number'],
'paged' => isset( $_GET['paged'] ) ? $_GET['paged'] : 1,
];
if ( ! empty( $atts['ids'] ) ) {
$query_args['post__in'] = array_map( 'trim', explode( ',', $atts['ids'] ) );
}
if ( ! empty( $atts['seller'] ) ) {
$query_args['meta_key'] = '_al_listing_seller';
$query_args['meta_value'] = absint( $atts['seller'] );
$query_args['meta_compare'] = '=';
}
// if we are in compact mode.
if ( ! empty( $atts['compact'] ) && 'true' === $atts['compact'] ) {
remove_action( 'auto_listings_listings_loop_item', 'auto_listings_template_loop_at_a_glance', 20 );
remove_action( 'auto_listings_listings_loop_item', 'auto_listings_template_loop_description', 50 );
add_filter( 'post_class', [ $this, 'listings_compact_mode' ] );
}
if ( ! empty( $atts['columns'] ) ) {
add_filter( 'auto_listings_columns', function() use ( $atts ) {
return $atts['columns'];
} );
}
return $this->listing_loop( $query_args, $atts );
}
Code file location:
auto-listings/auto-listings/src/Shortcodes.php
Auto Listings [mb_frontend_dashboard] Shortcode
The ‘mb_frontend_dashboard’ shortcode from Meta Box plugin is designed to create a user-friendly frontend dashboard. This shortcode checks if the user is logged in and displays an error message if not. It also retrieves and validates the attributes for the edit page. It sets up the dashboard with columns for title, date, and status. It also allows for customization of column headers and the action link for the post title. Additionally, it includes an option to display a welcome message. The output is then returned and displayed to the user.
Shortcode: [mb_frontend_dashboard]
Parameters
Here is a list of all possible mb_frontend_dashboard shortcode parameters and attributes:
id
– Unique identifier for the meta box.edit_page
– Identifies the page where edits are made.add_new
– Text displayed on the ‘Add New’ button.force_delete
– If set to true, posts are permanently deleted.columns
– Determines which columns to display.label_title
– Text for the title column header.label_date
– Text for the date column header.label_status
– Text for the status column header.label_actions
– Text for the actions column header.title_link
– Defines the action for post title link.show_welcome_message
– If set to true, displays a welcome message.
Examples and Usage
Basic example – Utilizing the shortcode to display the frontend dashboard for logged-in users.
[mb_frontend_dashboard id="dashboard" /]
Advanced examples
Here, the shortcode is used to display the frontend dashboard with a custom ‘Add New’ button text, and only the title, date, and status columns are shown. The ‘force_delete’ option is set to ‘true’, which means deleted posts will be removed permanently.
[mb_frontend_dashboard id="dashboard" add_new="Create New Post" columns="title,date,status" force_delete="true" /]
In this example, the shortcode is used to display the frontend dashboard without the welcome message. The ‘title_link’ option is set to ‘edit’, which means clicking on the post title will take the user to the edit post page.
[mb_frontend_dashboard id="dashboard" show_welcome_message="false" title_link="edit" /]
This example shows the shortcode being used to display the frontend dashboard with custom labels for the column headers.
[mb_frontend_dashboard id="dashboard" label_title="Post Title" label_date="Published Date" label_status="Current Status" label_actions="Available Actions" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [mb_frontend_dashboard]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'mb_frontend_dashboard', [ $this, 'shortcode' ] );
Shortcode PHP function:
function shortcode( $atts ) {
/*
* Do not render the shortcode in the admin.
* Prevent errors with enqueue assets in Gutenberg where requests are made via REST to preload the post content.
*/
if ( is_admin() ) {
return '';
}
if ( ! is_user_logged_in() ) {
return esc_html__( 'Please login to view the dashboard.', 'mb-frontend-submission' );
}
$this->edit_page_atts = $this->get_edit_page_attrs( $atts['edit_page'] );
if ( is_wp_error( $this->edit_page_atts ) ) {
return '<div class="rwmb-error">' . $this->edit_page_atts->get_error_message() . '</div>';
}
$atts = shortcode_atts( [
// Meta box id.
'id' => $this->edit_page_atts['id'],
// Edit page id.
'edit_page' => '',
// Add new post button text
'add_new' => __( 'Add New', 'mb-frontend-submission' ),
// Delete permanently.
'force_delete' => 'false',
// Columns to display.
'columns' => 'title,date,status',
// Column header labels.
'label_title' => __( 'Title', 'mb-frontend-submission' ),
'label_date' => __( 'Date', 'mb-frontend-submission' ),
'label_status' => __( 'Status', 'mb-frontend-submission' ),
'label_actions' => __( 'Actions', 'mb-frontend-submission' ),
// Link action for post title (view|edit).
'title_link' => '',
// Flag to hide/show welcome message.
'show_welcome_message' => 'true',
], $atts );
ob_start();
$this->query_posts();
if ( $atts['show_welcome_message'] === 'true' ) {
$this->show_welcome_message();
}
$this->show_user_posts( $atts );
return ob_get_clean();
}
Code file location:
auto-listings/auto-listings/vendor/meta-box/mb-frontend-submission/src/Dashboard.php
Conclusion
Now that you’ve learned how to embed the Auto Listings Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply