WP Directory Kit Shortcodes

Below, you’ll find a detailed guide on how to add the WP Directory Kit 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 WP Directory Kit Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the WP Directory Kit Plugin and the shortcodes it provides:

Plugin Icon
WP Directory Kit

"WP Directory Kit is a powerful, user-friendly WordPress plugin designed to create, manage, and customize directories on your website with ease."

★★★★★ (23) Active Installs: 2000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [wdk-latest-listings-list]
  • [wdk-listing-field-label]
  • [wdk-listing-field-value-prefix]
  • [wdk-listing-field-value-suffix]
  • [wdk-listing-field-value-text]
  • [link]
  • [wdk-listing-field-value]
  • [wdk-listing-fields-section]
  • [wdk-return-post-id]

WP Directory Kit [wdk-latest-listings-list] Shortcode

The WpDirectoryKit plugin shortcode, ‘wdk-latest-listings-list’, displays the latest listings on your site. It allows customization of listing features, including order, limit, and featured status. It also offers options for specific query configurations and CSS styling. The shortcode ensures the displayed listings are activated and approved, providing reliable content for your visitors.

Shortcode: [wdk-latest-listings-list]

Parameters

Here is a list of all possible wdk-latest-listings-list shortcode parameters and attributes:

  • id – Identifier for the specific listing.
  • custom_class – Custom CSS class for styling the listing.
  • order – Determines the order of the listings displayed.
  • conf_query – Configures the query parameters for the listing.
  • limit – Sets the maximum number of listings to display.
  • only_is_featured – If set to ‘yes’, only featured listings will be displayed.
  • conf_custom_results – Provides custom results based on specific criteria.

Examples and Usage

Basic example – Display the latest listings with a limit of 2 entries.

[wdk-latest-listings-list limit=2 /]

Advanced examples

Display the latest listings with a custom CSS class, ordered by date, and only showing featured listings.

[wdk-latest-listings-list custom_class="my-custom-class" order="date" only_is_featured="yes" /]

Display the latest listings with a limit of 5 entries, ordered by title, and with a custom query configuration.

[wdk-latest-listings-list limit=5 order="title" conf_query="category=hotels&location=paris" /]

Display the latest listings with a limit of 3 entries, and only showing the listings from a custom results set.

[wdk-latest-listings-list limit=3 conf_custom_results="1,2,3" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wdk-latest-listings-list] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wdk-latest-listings-list', 'shortcode_latest_listings_list');

Shortcode PHP function:

function shortcode_latest_listings_list($atts, $content){
    $atts = shortcode_atts(array(
        'id'=>NULL,
        'custom_class'=>'',
        'order'=>'',
        'conf_query'=>'',
        'limit'=>'2',
        'only_is_featured'=>'',
        'conf_custom_results'=>'',
    ), $atts);
    $data = array();

    /* settings from atts */
    $data['settings'] = $atts;
    $data['id_element'] = '';

    $data['listings_count'] = 0;
    $data['results'] = array();
    $data['pagination_output'] = '';


    /* load css/js */
    wp_enqueue_style('wdk-listings-list');

    $WMVC = &wdk_get_instance();
    $WMVC->model('listingfield_m');
    $WMVC->model('listing_m');
    $WMVC->load_helper('listing');
    $columns = array('ID', 'location_id', 'category_id', 'post_title', 'post_date', 'search', 'order_by','is_featured', 'address');
    $external_columns = array('location_id', 'category_id', 'post_title');
    
    if(!empty($data['settings']['conf_custom_results'])) {
        /* where in */
        if(!empty($listings_ids)){
            $WMVC->db->where( $WMVC->db->prefix.'wdk_listings.post_id IN(' . $data['settings']['conf_custom_results']  . ')', null, false);
            $data['results'] = $WMVC->listing_m->get();
        }
    } else {
        $controller = 'listing';
        $offset = NULL;
        $original_GET = wmvc_xss_clean($_GET);
        $_GET =  array();

        $_GET['order_by'] = $data['settings']['order'];

        if(!empty($data['settings']['conf_query'])) {
            $qr_string = trim($data['settings']['conf_query'],'?');
            parse_str($qr_string, $_GET);
            $_GET = array_map('trim', $_GET);
        }
        if($data['settings']['only_is_featured'] == 'yes') {
            $_GET['is_featured'] = 'on';
        }

        wdk_prepare_search_query_GET($columns, $controller.'_m', $external_columns);
        $data['results'] = $WMVC->listing_m->get_pagination($data['settings']['limit'], $offset, array('is_activated' => 1,'is_approved'=>1));

    }  
    
    if(isset($original_GET))
        $_GET = $original_GET;

    return wdk_shortcodes_view('shortcode-latest-listings-list', $data);;
}

Code file location:

wpdirectorykit/wpdirectorykit/shortcodes/shortcode-latest-listings-list.php

WP Directory Kit [wdk-listing-field-label] Shortcode

The WpDirectoryKit shortcode is a tool that retrieves and displays the label of a specific listing field. The shortcode utilizes the ‘field_id’ attribute to identify the desired field and returns its label. It supports HTML, allowing customization for a seamless fit into your website’s design. This shortcode is versatile and essential for any WordPress site using the WpDirectoryKit plugin, enabling users to fetch and display specific listing field labels effortlessly.

Shortcode: [wdk-listing-field-label]

Parameters

Here is a list of all possible wdk-listing-field-label shortcode parameters and attributes:

  • id – A unique identifier for the shortcode.
  • field_id – Specifies the field’s unique identifier.
  • post_id – Refers to the unique identifier of the post.
  • enable_html – Determines if HTML is enabled or not.

Examples and Usage

Basic example – The shortcode displays the label of a specific listing field by referencing its ID.

[wdk-listing-field-label field_id=1 /]

Advanced examples

Using the shortcode to display the label of a specific listing field by referencing its ID and post ID. This will load the label of the field from the specific post.

[wdk-listing-field-label field_id=1 post_id=10 /]

Another advanced usage can be to enable HTML in the label. The ‘enable_html’ attribute can be set to ‘true’ to allow HTML in the label.

[wdk-listing-field-label field_id=1 enable_html=true /]

These examples demonstrate the flexibility and power of the ‘wdk-listing-field-label’ shortcode. By adjusting the attributes, you can customize the shortcode to suit your specific needs.

PHP Function Code

In case you have difficulties debugging what causing issues with [wdk-listing-field-label] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wdk-listing-field-label', 'shortcode_wdk_listing_field_label');

Shortcode PHP function:

function shortcode_wdk_listing_field_label($atts, $content){
    $atts = shortcode_atts(array(
        'id'=>NULL,
        'field_id'=>'',
        'post_id'=>'',
        'enable_html'=>'',
    ), $atts);
    $data = array();

    /* settings from atts */
    $data['settings'] = $atts;
    $data['id_element'] = '';

    /* load css/js */

    $WMVC = &wdk_get_instance();
    $WMVC->model('listingfield_m');
    $WMVC->model('listing_m');
    $WMVC->load_helper('listing');
    
    $data['field_label'] = '';
    if(!empty($data['settings']['field_id'])) {
        $data['field_label'] = wdk_field_label($data['settings']['field_id']);
    }

    return wdk_shortcodes_view('shortcode-wdk-listing-field-label', $data);
}

Code file location:

wpdirectorykit/wpdirectorykit/shortcodes/shortcode-wdk-listing-field-label.php

WP Directory Kit [wdk-listing-field-value-prefix] Shortcode

The WpDirectoryKit shortcode is designed to fetch and display specific field values from a listing. This shortcode allows users to retrieve and display the value of a specific field in a listing. It can also add a prefix or suffix to the field value. The shortcode takes parameters like ‘id’, ‘field_id’, ‘post_id’, and ‘enable_html’. It checks if the field value is not empty, and if so, it displays the field value with the specified prefix or suffix.

Shortcode: [wdk-listing-field-value-prefix]

Parameters

Here is a list of all possible wdk-listing-field-value-prefix shortcode parameters and attributes:

  • id – Unique identifier for the shortcode instance.
  • field_id – Represents the specific field in a listing.
  • post_id – Specifies the ID of the post where the listing is displayed.
  • enable_html – Allows or disallows HTML in the field value.

Examples and Usage

Basic example – Display a listing field value with a specified prefix.

[wdk-listing-field-value-prefix id="1" field_id="field_1" /]

Advanced examples

Display a listing field value with a specified prefix and post ID. This shortcode will first try to load by post ID. If not found, it will try to load by field ID.

[wdk-listing-field-value-prefix id="1" field_id="field_1" post_id="post_1" /]

Display a listing field value with a specified prefix, post ID, and enable HTML. This shortcode will first try to load by post ID and field ID. If not found, it will try to load by enabling HTML.

[wdk-listing-field-value-prefix id="1" field_id="field_1" post_id="post_1" enable_html="true" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wdk-listing-field-value-prefix] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wdk-listing-field-value-prefix', 'shortcode_wdk_listing_field_value_prefix');

Shortcode PHP function:

function shortcode_wdk_listing_field_value_prefix($atts, $content){
    $atts = shortcode_atts(array(
        'id'=>NULL,
        'field_id'=>'',
        'post_id'=>'',
        'enable_html'=>'',
    ), $atts);
    $data = array();

    /* settings from atts */
    $data['settings'] = $atts;
    $data['id_element'] = '';

    /* load css/js */

    $WMVC = &wdk_get_instance();
    $WMVC->model('listingfield_m');
    $WMVC->model('listing_m');
    $WMVC->load_helper('listing');
    global $wdk_listing_id;
    $post_id = $wdk_listing_id;
    if (!empty($data['settings']['post_id'])) {
        $post_id = $data['settings']['post_id'];
    }
    
    $data['field_value'] = '';
    $data['field_prefix'] = '';
    $data['field_suffix'] = '';
    if(!empty($data['settings']['field_id'])){
        if(strpos($data['settings']['field_id'],'__') !== FALSE){
            $data['settings']['field_id'] = substr($data['settings']['field_id'], strpos($data['settings']['field_id'],'__')+2);
        }

        $data['field_prefix'] =  wdk_field_option ($data['settings']['field_id'], 'prefix');
        $data['field_suffix'] =  wdk_field_option ($data['settings']['field_id'], 'suffix');
    }

    $data['is_edit_mode']= false;          

    /* return false if no content */
    if(wdk_field_value($data['settings']['field_id'], $post_id) == '')
        return false;
        
    $data['field_prefix'] = apply_filters( 'wpdirectorykit/listing/field/prefix', $data['field_prefix'], $data['settings']['field_id']);

    return wdk_shortcodes_view('shortcode-wdk-listing-field-value-prefix', $data);
}

Code file location:

wpdirectorykit/wpdirectorykit/shortcodes/shortcode-wdk-listing-field-value-prefix.php

WP Directory Kit [wdk-listing-field-value-suffix] Shortcode

The WPDirectoryKit shortcode, ‘wdk-listing-field-value-suffix’, is designed to fetch and display the suffix of a given field from a listing. It extracts the ‘field_id’ from the attributes, checks if the field has a suffix, and retrieves it. If the field value is empty, it returns false. The suffix can be modified through a filter.

Shortcode: [wdk-listing-field-value-suffix]

Parameters

Here is a list of all possible wdk-listing-field-value-suffix shortcode parameters and attributes:

  • id – Unique identifier for the shortcode instance.
  • field_id – Specifies the field to retrieve the value from.
  • enable_html – Allows HTML content in the field value.
  • post_id – Specifies the post to retrieve the field value from.

Examples and Usage

Basic example – Display a listing field value with its suffix using the listing field ID.

[wdk-listing-field-value-suffix field_id="price" /]

Advanced examples

Display a listing field value with its suffix, specifying the post ID and enabling HTML in the output.

[wdk-listing-field-value-suffix field_id="description" enable_html="true" post_id="123" /]

Display a listing field value with its suffix, using a field ID that includes a prefix, and specifying the post ID.

[wdk-listing-field-value-suffix field_id="listing__price" post_id="456" /]

The ‘wdk-listing-field-value-suffix’ shortcode is versatile and can be customized with different parameters to suit your needs. Whether you want to display a simple listing field value with its suffix or need to include more advanced parameters such as the post ID and HTML enablement, this shortcode has got you covered.

PHP Function Code

In case you have difficulties debugging what causing issues with [wdk-listing-field-value-suffix] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wdk-listing-field-value-suffix', 'shortcode_wdk_listing_field_value_suffix');

Shortcode PHP function:

function shortcode_wdk_listing_field_value_suffix($atts, $content){
    $atts = shortcode_atts(array(
        'id'=>NULL,
        'field_id'=>'',
        'enable_html'=>'',
        'post_id'=>'',
    ), $atts);
    $data = array();

    /* settings from atts */
    $data['settings'] = $atts;
    $data['id_element'] = '';

    /* load css/js */

    $WMVC = &wdk_get_instance();
    $WMVC->model('listingfield_m');
    $WMVC->model('listing_m');
    $WMVC->load_helper('listing');
    global $wdk_listing_id;
    $post_id = $wdk_listing_id;
    if (!empty($data['settings']['post_id'])) {
        $post_id = $data['settings']['post_id'];
    }
    
    $data['field_value'] = '';
    $data['field_suffix'] = '';
    $data['field_suffix'] = '';
    if(!empty($data['settings']['field_id'])){
        if(strpos($data['settings']['field_id'],'__') !== FALSE){
            $data['settings']['field_id'] = substr($data['settings']['field_id'], strpos($data['settings']['field_id'],'__')+2);
        }

        $data['field_suffix'] =  wdk_field_option ($data['settings']['field_id'], 'suffix');
        $data['field_suffix'] =  wdk_field_option ($data['settings']['field_id'], 'suffix');
    }

    $data['is_edit_mode']= false;          

    /* return false if no content */
    if(wdk_field_value($data['settings']['field_id'], $post_id) == '')
        return false;
        
    $data['field_suffix'] = apply_filters( 'wpdirectorykit/listing/field/suffix', $data['field_suffix'], $data['settings']['field_id']);

    return wdk_shortcodes_view('shortcode-wdk-listing-field-value-suffix', $data);
}

Code file location:

wpdirectorykit/wpdirectorykit/shortcodes/shortcode-wdk-listing-field-value-suffix.php

WP Directory Kit [wdk-listing-field-value-text] Shortcode

The WpDirectoryKit shortcode enables the display of specific field values for a listing. It fetches data based on parameters like ‘id’, ‘field_id’, ‘post_id’, etc. This shortcode handles different types of field values including checkboxes, input boxes, and URLs. It also supports video embeds from YouTube and Vimeo. If the field value is empty, it returns false.

Shortcode: [wdk-listing-field-value-text]

Parameters

Here is a list of all possible wdk-listing-field-value-text shortcode parameters and attributes:

  • id – A unique identifier for the form.
  • field_id – Specifies the field within the listing to display.
  • post_id – Specifies the post to fetch the listing from.
  • enable_html – Allows HTML content in the field value.
  • norender – If set to 1, the shortcode will return raw data instead of rendering it.

Examples and Usage

Basic example – Displaying a listing field value by referencing the field ID.

[wdk-listing-field-value-text field_id="field_1" /]

Advanced examples

Using the shortcode to display a listing field value by referencing both field ID and post ID. The value will be fetched from the specified post’s metadata.

[wdk-listing-field-value-text field_id="field_1" post_id="123" /]

Displaying a listing field value with HTML rendering enabled. The value will be outputted as HTML if it contains HTML tags.

[wdk-listing-field-value-text field_id="field_1" enable_html="true" /]

Displaying a listing field value without rendering. The value will be outputted as plain text, ignoring any HTML tags or special formatting.

[wdk-listing-field-value-text field_id="field_1" norender="true" /]

Using the shortcode to display a listing field value by referencing the field ID and specifying a custom ID for the shortcode output. The output will be wrapped in a div with the specified ID.

[wdk-listing-field-value-text id="custom_id" field_id="field_1" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wdk-listing-field-value-text] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wdk-listing-field-value-text', 'shortcode_wdk_listing_field_value_text');

Shortcode PHP function:

function shortcode_wdk_listing_field_value_text($atts, $content){
    $atts = shortcode_atts(array(
        'id'=>NULL,
        'field_id'=>'',
        'post_id'=>'',
        'enable_html'=>'',
        'norender'=>'',
    ), $atts);
    $data = array();

    /* settings from atts */
    $data['settings'] = $atts;
    $data['id_element'] = '';

    /* load css/js */

    $WMVC = &wdk_get_instance();
    $WMVC->model('listingfield_m');
    $WMVC->model('listing_m');
    $WMVC->load_helper('listing');
    global $wdk_listing_id;
    $post_id = $wdk_listing_id;
    if (!empty($data['settings']['post_id'])) {
        $post_id = $data['settings']['post_id'];
    }
    
    $data['field_value'] = '';
    $data['field_prefix'] = '';
    $data['field_suffix'] = '';
    if(!empty($data['settings']['field_id'])){
        if(strpos($data['settings']['field_id'],'__') !== FALSE){
            $data['settings']['field_id'] = substr($data['settings']['field_id'], strpos($data['settings']['field_id'],'__')+2);
        }

        if($data['settings']['norender'] == 1) {
            $data['field_value'] = wdk_field_value ($data['settings']['field_id'], $post_id);
        } elseif(wdk_field_option($data['settings']['field_id'], 'field_type') == "CHECKBOX") {
            if(wdk_field_value ($data['settings']['field_id'], $post_id) == 1){
                $data['field_value'] = '<span class="field_checkbox_success"><span class="label label-success"><span class="dashicons dashicons-saved"></span></span></span>';
            } else {
                $data['field_value'] = '<span class="field_checkbox_unsuccess"><span class="label label-success"><span class="dashicons dashicons-unsaved"></span></span></span>';
            }  
        } else if(wdk_field_option($data['settings']['field_id'],'field_type') == "INPUTBOX") {
            $data['field_value'] = wdk_field_value ($data['settings']['field_id'], $post_id);

            if(strpos($data['field_value'], 'vimeo.com') !== FALSE)
            {
                    $data['field_value'] = wp_oembed_get($data['field_value'], array("width"=>"800", "height"=>"450"));
            }
            elseif(strpos($data['field_value'], 'watch?v=') !== FALSE)
            {
                $embed_code = substr($data['field_value'], strpos($data['field_value'], 'watch?v=')+8);
                $data['field_value'] =  wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
            }
            elseif(strpos($data['field_value'], 'youtu.be/') !== FALSE)
            {
                $embed_code = substr($data['field_value'], strpos($data['field_value'], 'youtu.be/')+9);
                $data['field_value'] = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
            } 
            elseif(filter_var($data['field_value'], FILTER_VALIDATE_URL) !== FALSE && preg_match('/\.(mp4|flv|wmw|ogv|webm|ogg)$/i', $data['field_value']))
            {
                $data['field_value']  = '<video src="'.$data['field_value'].'" controls></video> ';
            }
            elseif(filter_var($data['field_value'] , FILTER_VALIDATE_URL) !== FALSE) {
                $data['field_value']  = '<a href="'.$data['field_value'] .'">'.wdk_field_label($data['settings']['field_id']).'</a>';
            }
        }
        elseif($data['settings']['field_id'] == 'category_id') {
            if(wdk_field_value ($data['settings']['field_id'], $post_id)){
                $WMVC->model('category_m');
                $tree_data = $WMVC->category_m->get(wdk_field_value ($data['settings']['field_id'], $post_id), TRUE);
                $data['field_value'] = wmvc_show_data('category_title', $tree_data);
            }
        }
        elseif($data['settings']['field_id'] == 'location_id') {
            if(wdk_field_value ($data['settings']['field_id'], $post_id)){
                $WMVC->model('location_m');
                $tree_data = $WMVC->location_m->get(wdk_field_value ($data['settings']['field_id'], $post_id), TRUE);
                $data['field_value'] = wmvc_show_data('location_title', $tree_data);
            }
        }
        else {
            $data['field_value'] = wdk_field_value ($data['settings']['field_id'], $post_id);
        }
   
        $data['field_prefix'] =  wdk_field_option ($data['settings']['field_id'], 'prefix');
        $data['field_suffix'] =  wdk_field_option ($data['settings']['field_id'], 'suffix');
    }

    $data['is_edit_mode']= false;          

    /* return false if no content */
    if(wdk_field_value($data['settings']['field_id'], $post_id) == '')
        return false;
        
    $data['field_value'] = apply_filters( 'wpdirectorykit/listing/field/value', (wmvc_show_data('value', $data['field_value'])), $data['settings']['field_id']);

    if($data['settings']['norender'] == 1) {
        return 'https://www.youtube.com/embed/cewZBOGzbPg';
        //echo $data['field_value'];
    } else {
        return wdk_shortcodes_view('shortcode-wdk-listing-field-value-text', $data);
    }
}

Code file location:

wpdirectorykit/wpdirectorykit/shortcodes/shortcode-wdk-listing-field-value-text.php

WP Directory Kit [link] Shortcode

The ‘link’ shortcode from the wpdirectorykit plugin is a handy tool to create hyperlinks. This shortcode allows you to specify the URL and the anchor text within your WordPress post. When implemented, it generates an HTML ‘a’ tag with the specified URL and anchor text. The ‘url’ attribute determines the destination of the link, while ‘text’ sets the clickable text.

Shortcode: [link]

Parameters

Here is a list of all possible link shortcode parameters and attributes:

  • url – The web address that the link will direct to
  • text – The clickable text displayed for the hyperlink

Examples and Usage

Basic example – A simple usage of the shortcode to create a link with default text and URL.

[link /]

By using the shortcode in this way, a link with the text “Click Here” and a URL of “#” will be generated. This is useful when you want to provide a default link, but don’t have a specific URL or text in mind.

Advanced examples

Using the shortcode to create a link with custom text and URL.

[link url="https://example.com" text="Visit Example.com" /]

In this example, the shortcode is used to create a link with the text “Visit Example.com” and a URL of “https://example.com”. This is useful when you want to provide a specific link and text to your users.

Using the shortcode to create multiple links with different texts and URLs.

[link url="https://example1.com" text="Visit Example1.com" /]
[link url="https://example2.com" text="Visit Example2.com" /]

In this example, the shortcode is used to create multiple links with different texts and URLs. This is useful when you want to provide multiple links to your users, each with their own specific text and URL.

PHP Function Code

In case you have difficulties debugging what causing issues with [link] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'link', 'link_shortcode' );

Shortcode PHP function:

function link_shortcode( $atts, $content = null ) {
    extract( shortcode_atts( array(
        'url' => '#',
        'text' => 'Click Here'
    ), $atts ) );
    return '<a href="' . esc_url( $url ) . '">' . esc_attr( $text ) . '</a>';
}

Code file location:

wpdirectorykit/wpdirectorykit/shortcodes/shortcode-wdk-listing-field-value-text.php

WP Directory Kit [wdk-listing-field-value] Shortcode

The WP Directory Kit plugin shortcode ‘wdk-listing-field-value’ is designed to extract and display specific field values from a listing. It provides flexibility in displaying content such as checkboxes, input boxes, and specific categories or locations. Additionally, it handles various data types, including embedded videos and URLs. The shortcode also allows for customization of field prefixes and suffixes.

Shortcode: [wdk-listing-field-value]

Parameters

Here is a list of all possible wdk-listing-field-value shortcode parameters and attributes:

  • id – The unique identifier of the shortcode
  • field_id – Specifies the field in the post to retrieve the value from
  • post_id – Specifies the post from which the field value will be retrieved
  • enable_html – Determines whether HTML is allowed in the field value or not

Examples and Usage

Basic example – A shortcode to display a specific field value from a listing by referencing the field ID and post ID.

[wdk-listing-field-value field_id="field_1" post_id="123" /]

Advanced examples

Displaying a specific field value with HTML enabled. When the ‘enable_html’ attribute is set to ‘yes’, any HTML content within the field value will be rendered.

[wdk-listing-field-value field_id="field_1" post_id="123" enable_html="yes" /]

Using the shortcode to display a specific field value from a listing by referencing the field ID, post ID, and custom ID. The custom ID can be used for CSS styling or JavaScript targeting.

[wdk-listing-field-value id="custom_1" field_id="field_1" post_id="123" /]

Displaying a specific field value from a listing by referencing the field ID and post ID, with a prefix and suffix added to the field value. The prefix and suffix can be used for adding units or other contextual information to the field value.

[wdk-listing-field-value field_id="field_1" post_id="123" prefix="$" suffix=" per month" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wdk-listing-field-value] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wdk-listing-field-value', 'shortcode_wdk_listing_field_value');

Shortcode PHP function:

function shortcode_wdk_listing_field_value($atts, $content){
    $atts = shortcode_atts(array(
        'id'=>NULL,
        'field_id'=>'',
        'post_id'=>'',
        'enable_html'=>'',
    ), $atts);
    $data = array();

    /* settings from atts */
    $data['settings'] = $atts;
    $data['id_element'] = '';

    /* load css/js */

    $WMVC = &wdk_get_instance();
    $WMVC->model('listingfield_m');
    $WMVC->model('listing_m');
    $WMVC->load_helper('listing');
    global $wdk_listing_id;
    $post_id = $wdk_listing_id;
    if (!empty($data['settings']['post_id'])) {
        $post_id = $data['settings']['post_id'];
    }
    
    $data['field_value'] = '';
    $data['field_prefix'] = '';
    $data['field_suffix'] = '';
    if(!empty($data['settings']['field_id'])){
        if(strpos($data['settings']['field_id'],'__') !== FALSE){
            $data['settings']['field_id'] = substr($data['settings']['field_id'], strpos($data['settings']['field_id'],'__')+2);
        }

        if(wdk_field_option($data['settings']['field_id'], 'field_type') == "CHECKBOX") {
            if(wdk_field_value ($data['settings']['field_id'], $post_id) == 1){
                $data['field_value'] = '<span class="field_checkbox_success"><span class="label label-success"><span class="dashicons dashicons-saved"></span></span></span>';
            } else {
                $data['field_value'] = '<span class="field_checkbox_unsuccess"><span class="label label-success"><span class="dashicons dashicons-unsaved"></span></span></span>';
            } 
        } else if(wdk_field_option($data['settings']['field_id'],'field_type') == "INPUTBOX") {
            $data['field_value'] = wdk_field_value ($data['settings']['field_id'], $post_id);

            if(strpos($data['field_value'], 'vimeo.com') !== FALSE)
            {
                    $data['field_value'] = wp_oembed_get($data['field_value'], array("width"=>"800", "height"=>"450"));
            }
            elseif(strpos($data['field_value'], 'watch?v=') !== FALSE)
            {
                $embed_code = substr($data['field_value'], strpos($data['field_value'], 'watch?v=')+8);
                $data['field_value'] =  wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
            }
            elseif(strpos($data['field_value'], 'youtu.be/') !== FALSE)
            {
                $embed_code = substr($data['field_value'], strpos($data['field_value'], 'youtu.be/')+9);
                $data['field_value'] = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
            } 
            elseif(filter_var($data['field_value'], FILTER_VALIDATE_URL) !== FALSE && preg_match('/\.(mp4|flv|wmw|ogv|webm|ogg)$/i', $data['field_value']))
            {
                $data['field_value']  = '<video src="'.$data['field_value'].'" controls></video> ';
            }
            elseif(filter_var($data['field_value'] , FILTER_VALIDATE_URL) !== FALSE) {
                $data['field_value']  = '<a href="'.$data['field_value'] .'">'.wdk_field_label($data['settings']['field_id']).'</a>';
            }
        }
        elseif($data['settings']['field_id'] == 'category_id') {
            if(wdk_field_value ($data['settings']['field_id'], $post_id)){
                $WMVC->model('category_m');
                $tree_data = $WMVC->category_m->get(wdk_field_value ($data['settings']['field_id'], $post_id), TRUE);
                $data['field_value'] = wmvc_show_data('category_title', $tree_data);
            }
        }
        elseif($data['settings']['field_id'] == 'location_id') {
            if(wdk_field_value ($data['settings']['field_id'], $post_id)){
                $WMVC->model('location_m');
                $tree_data = $WMVC->location_m->get(wdk_field_value ($data['settings']['field_id'], $post_id), TRUE);
                $data['field_value'] = wmvc_show_data('location_title', $tree_data);
            }
        }
        else {
            $data['field_value'] = wdk_field_value ($data['settings']['field_id'], $post_id);
        }
   
        $data['field_prefix'] =  wdk_field_option ($data['settings']['field_id'], 'prefix');
        $data['field_suffix'] =  wdk_field_option ($data['settings']['field_id'], 'suffix');
    }

    $data['is_edit_mode']= false;          

    /* return false if no content */
    if(wdk_field_value($data['settings']['field_id'], $post_id) == '')
        return false;
        
    $data['field_prefix'] = apply_filters( 'wpdirectorykit/listing/field/prefix', $data['field_prefix'], $data['settings']['field_id']);
    $data['field_value'] = apply_filters( 'wpdirectorykit/listing/field/value', (wmvc_show_data('value', $data['field_value'])), $data['settings']['field_id']);
    $data['field_suffix'] = apply_filters( 'wpdirectorykit/listing/field/suffix',$data['field_suffix'], $data['settings']['field_id']);

    return wdk_shortcodes_view('shortcode-wdk-listing-field-value', $data);
}

Code file location:

wpdirectorykit/wpdirectorykit/shortcodes/shortcode-wdk-listing-field-value.php

WP Directory Kit [wdk-listing-fields-section] Shortcode

The WPDIRECTORYKIT shortcode is a powerful tool that dynamically generates a specific section of listing fields. It customizes attributes like ‘id’, ‘section_id’, ‘post_id’, and more. The PHP function associated with this shortcode loads necessary models and helpers, fetches the desired section and field data, and checks for content availability. If the section is empty and ‘hide_onempty_complete’ is set to ‘yes’, it returns false. Shortcode: [shortcode_wdk_listing_fields_section] This shortcode is ideal for creating customized, dynamic sections in your WordPress directory listings.

Shortcode: [wdk-listing-fields-section]

Parameters

Here is a list of all possible wdk-listing-fields-section shortcode parameters and attributes:

  • id – Unique identifier for the shortcode instance.
  • section_id – Determines the section of the listing fields to display.
  • post_id – Specifies the post to pull listing field data from.
  • field_label_hide – Controls if the field label is hidden.
  • label_suffix – Text added after the label.
  • label_prefix – Text added before the label.
  • field_group_icon_enable – Decides if field group icons are displayed.
  • hide_onempty_complete – Hides the section if all fields are empty.
  • custom_class – Allows for custom CSS classes to be added.

Examples and Usage

Basic example – Show a specific section of a listing by providing the section ID.

[wdk-listing-fields-section section_id="1" /]

Advanced examples

Display a specific section of a listing by providing the section ID, and also specify the Post ID to fetch the data from, and hide the label of the field.

[wdk-listing-fields-section section_id="1" post_id="123" field_label_hide="yes" /]

Display a specific section of a listing by providing the section ID, specify the Post ID to fetch the data from, hide the label of the field, and also add a custom CSS class to the section.

[wdk-listing-fields-section section_id="1" post_id="123" field_label_hide="yes" custom_class="my-custom-class" /]

Display a specific section of a listing by providing the section ID, specify the Post ID to fetch the data from, hide the label of the field, add a custom CSS class to the section, and hide the section if all fields are empty.

[wdk-listing-fields-section section_id="1" post_id="123" field_label_hide="yes" custom_class="my-custom-class" hide_onempty_complete="yes" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wdk-listing-fields-section] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wdk-listing-fields-section', 'shortcode_wdk_listing_fields_section');

Shortcode PHP function:

function shortcode_wdk_listing_fields_section($atts, $content){
    $atts = shortcode_atts(array(
        'id'=>NULL,
        'section_id'=>'',
        'post_id'=>'',
        'field_label_hide'=>'',
        'label_suffix'=>':',
        'label_prefix'=>'',
        'field_group_icon_enable'=>'no',
        'hide_onempty_complete'=>'yes',
        'custom_class'=>'',
    ), $atts);
    $data = array();

    /* settings from atts */
    $data['settings'] = $atts;
    $data['id_element'] = '';

    /* load css/js */

    $WMVC = &wdk_get_instance();
    $WMVC->model('listingfield_m');
    $WMVC->model('field_m');
    $WMVC->model('listing_m');
    $WMVC->load_helper('listing');

    global $wdk_listing_id;
    $post_id = $wdk_listing_id;
    if (!empty($data['settings']['post_id'])) {
        $post_id = $data['settings']['post_id'];
    }

    $data['post_id'] = $post_id;
    
    $data['section_label'] = 'Example Section';
    $data['sections_data'] =  $WMVC->field_m->get_fields_section();
    $data['section_data'] =  array();

    if(!empty($data['settings']['section_id'])){
        $data['section_label'] = wdk_field_label($data['settings']['section_id']);
        if(isset($data['sections_data'][$data['settings']['section_id']]))
            $data['section_data'] =  $data['sections_data'][$data['settings']['section_id']];
    }

    if(!empty($data['settings']['field_id']))
        $data['field_label'] = wdk_field_label($data['settings']['field_id']);

    if(empty($data['section_data'])){
        return false;
    }     

    /* return false if no content */
    if($data['settings']['hide_onempty_complete'] == 'yes') {
        $complete_empty = true;
        foreach($data['section_data']['fields'] as $field) {

            if(wdk_field_value('category_id', $post_id) && wdk_depend_is_hidden_field(wmvc_show_data('idfield', $field), wdk_field_value('category_id', $post_id))) {
                continue;
            } 

            if(!empty(wdk_field_value (wmvc_show_data('idfield', $field), $post_id))){
                $complete_empty = false;
                break;
            }
        }

        if($complete_empty)
            return false;
    }

    return wdk_shortcodes_view('shortcode-wdk-listing-fields-section', $data);
}

Code file location:

wpdirectorykit/wpdirectorykit/shortcodes/shortcode-wdk-listing-fields-section.php

WP Directory Kit [wdk-return-post-id] Shortcode

The wdk-return-post-id shortcode is a flexible tool in the wpdirectorykit plugin. It retrieves the ID of a post, which can be useful in various scenarios. It first checks if there’s a defined ‘wdk_listing_result_id’ or ‘wdk_listing_id’. If either exists, it returns that value. If not, it defaults to the current post ID.

Shortcode: [wdk-return-post-id]

Parameters

Here is a list of all possible wdk-return-post-id shortcode parameters and attributes:

  • id – A unique identifier for a specific post or page.

Examples and Usage

Basic example – A simple usage of the shortcode to return the post ID.

[wdk-return-post-id /]

Advanced examples

Using the shortcode with a specific ID attribute. This will return the post ID of the post with the provided ID.

[wdk-return-post-id id=5 /]

Using the shortcode with multiple ID attributes. This will return the post IDs of the posts with the provided IDs. Note that the IDs should be separated by commas.

[wdk-return-post-id id=5,7,9 /]

Please note that the ‘wdk-return-post-id’ shortcode is designed to return the ID of the current post by default, if no ID attribute is provided. If an ID attribute is provided, the shortcode will return the post ID of the post with the corresponding ID. If multiple ID attributes are provided, the shortcode will return the post IDs of all the posts with the corresponding IDs.

PHP Function Code

In case you have difficulties debugging what causing issues with [wdk-return-post-id] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wdk-return-post-id', 'shortcode_wdk_return_post_id');

Shortcode PHP function:

function shortcode_wdk_return_post_id($atts, $content){
    $atts = shortcode_atts(array(
        'id'=>NULL,
    ), $atts);
    $data = array();

    /* settings from atts */
    $data['settings'] = $atts;
    $data['id_element'] = '';

    global $wdk_listing_result_id;
    if(!empty($wdk_listing_result_id))
        return $wdk_listing_result_id;
    
    global $wdk_listing_id;
    if(!empty($wdk_listing_id))
        return $wdk_listing_id;

    return get_the_ID();

}

Code file location:

wpdirectorykit/wpdirectorykit/shortcodes/shortcode-wdk-return-post-id.php

Conclusion

Now that you’ve learned how to embed the WP Directory Kit 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *