VK Filter Search Shortcodes

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

Before starting, here is an overview of the VK Filter Search Plugin and the shortcodes it provides:

Plugin Icon
VK Filter Search

"VK Filter Search is a powerful WordPress plugin that enhances your website's search functionality. It allows users to efficiently filter search results, significantly improving site navigation."

★★★★★ (3) Active Installs: 5000+ Tested with: 6.3.2 PHP Version: 7.4
Included Shortcodes:
  • [vk_filter_search]
  • [vk_filter_search_keyword class_name="your_class_name"]
  • [vk_filter_search_post_type]
  • [vk_filter_search_taxonomy]

VK Filter Search [vk_filter_search] Shortcode

The vk-filter-search shortcode allows users to create a customizable search form. It can be tailored to search specific post types and apply custom classes. The shortcode utilizes attributes like ‘class_name’ and ‘post_type’. The ‘class_name’ attribute allows users to add a custom class to the form, while ‘post_type’ specifies the post type to search. The form created by the shortcode includes hidden inputs for ‘post_type’ and ‘search keyword’, making it more flexible for advanced searches. The form also includes a submit button with the label ‘Search’. This shortcode provides a simple yet effective way to enhance the search functionality on your WordPress site.

Shortcode: [vk_filter_search]

Parameters

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

  • class_name – Additional CSS class for styling the search form
  • post_type – Filters search results based on the specified post type

Examples and Usage

Basic example – A simple usage of the vk_filter_search shortcode without any additional parameters.

[vk_filter_search /]

Advanced examples

Using the shortcode to display a search form specifically for posts. The ‘post_type’ attribute is used to specify the type of content to search.

[vk_filter_search post_type="post" /]

Adding a custom class to the search form. The ‘class_name’ attribute is used to add a custom class to the form. This can be useful for applying custom styles.

[vk_filter_search class_name="my_custom_class" /]

Combining both ‘post_type’ and ‘class_name’ attributes. This example shows how you can use multiple attributes within the same shortcode to customize the search form further.

[vk_filter_search class_name="my_custom_class" post_type="post" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'vk_filter_search', array( __CLASS__, 'add_search_form_shortcode' ) );

Shortcode PHP function:

function add_search_form_shortcode( $atts, $content ) {
		$atts = shortcode_atts(
			array(
				'class_name'  => '',
				'post_type'   => '',
			),
			$atts
		);

		$class_name  = ! empty( $atts['class_name'] ) ? ' ' . $atts['class_name'] : '';

		$form_before_html  = '<form class="vk-filter-search vkfs' . $class_name . '" method="get" action="' . home_url( '/' ) . '">';
		$form_before_html .= '<div class="vkfs__labels">';

		$inner_content = shortcode_unautop( $content );
		$content       = do_shortcode( $inner_content );

		$form_after_html = '</div>';
		if ( ! empty( $atts['post_type'] ) ) {
			$form_after_html .= '<input type="hidden" name="vkfs_post_type[]" value="' . $atts['post_type'] . '" />';
		}
		if ( false === strpos( $inner_content, 'vk_filter_search_keyword' ) ) {
			$form_after_html .= '<input type="hidden" name="s" value="" />';
		}
		$form_after_html .= '<input type="hidden" name="vkfs_submitted" value="true" />';
		$form_after_html .= '<input class="btn btn-primary" type="submit" value="' . __( 'Search', 'vk-filter-search' ) . '" />';
		$form_after_html .= '</form>';

		$search_form = $form_before_html . $content . $form_after_html;
		$search_form = preg_replace( '/\<p\>|\<\/p\>|\<br \/\>/', '', $search_form );

		return wp_kses( $search_form, VK_Filter_Search::kses_allowed() );
	}

Code file location:

vk-filter-search/vk-filter-search/inc/filter-search/package/class-vk-filter-search-shortcode.php

VK Filter Search [vk_filter_search_keyword] Shortcode

The VK Filter Search plugin shortcode, ‘vk_filter_search_keyword’, generates a keyword form. It’s customizable with a class name attribute to fit your site’s style. The PHP code associated with this shortcode allows the user to pass a ‘class_name’ attribute. This attribute is used to style the form. If no ‘class_name’ is provided, the form will default to its original styling. This shortcode simplifies the process of adding a keyword search form to your WordPress site.

Shortcode: [vk_filter_search_keyword class_name="your_class_name"]

Parameters

Here is a list of all possible vk_filter_search_keyword class_name=”your_class_name” shortcode parameters and attributes:

  • class_name – Specifies the CSS class of the keyword form.

Examples and Usage

Basic example – The shortcode below represents a simple usage of the vk_filter_search_keyword shortcode. Here, no additional parameters are used.

[vk_filter_search_keyword /]

For more advanced usage, we can pass additional parameters to the shortcode. The ‘class_name’ attribute allows you to specify a custom CSS class for the keyword form. This can be useful for custom styling.

Advanced examples

In the example below, we’re using the ‘class_name’ parameter to assign a custom CSS class to the keyword form. The class is named ‘my_custom_class’.

[vk_filter_search_keyword class_name='my_custom_class' /]

Further, you can chain multiple parameters in a single shortcode. In this example, we’re adding two custom classes ‘my_custom_class1’ and ‘my_custom_class2’ to the keyword form.

[vk_filter_search_keyword class_name='my_custom_class1 my_custom_class2' /]

Remember, the ‘class_name’ parameter accepts a string. If you want to add multiple classes, separate them with a space, as shown in the example above.

PHP Function Code

In case you have difficulties debugging what causing issues with [vk_filter_search_keyword class_name="your_class_name"] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'vk_filter_search_keyword', array( __CLASS__, 'add_keyword_form_shortcode' ) );

Shortcode PHP function:

function add_keyword_form_shortcode( $atts, $content ) {
		$atts = shortcode_atts(
			array(
				'class_name'  => '',
			),
			$atts
		);

		$options = array(
			'class_name' =>  ! empty( $atts['class_name'] ) ? $atts['class_name'] : '',
		);

		return VK_Filter_Search::get_keyword_form_html( $options );
	}

Code file location:

vk-filter-search/vk-filter-search/inc/filter-search/package/class-vk-filter-search-shortcode.php

VK Filter Search [vk_filter_search_post_type] Shortcode

The VK Filter Search Post Type shortcode allows users to customize the search filter for different post types. It accepts ‘post_types’ and ‘class_name’ as attributes. The ‘post_types’ attribute lets you specify the post types to include in the search filter. The ‘class_name’ attribute allows adding a custom CSS class.

Shortcode: [vk_filter_search_post_type]

Parameters

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

  • post_types – specifies the types of posts to be included in the search.
  • class_name – allows custom styling by assigning a specific CSS class.

Examples and Usage

Basic example – A simple usage of the shortcode to filter search results for posts and pages.

[vk_filter_search_post_type post_types="post,page" /]

Advanced examples:

Using the shortcode to filter search results for custom post types (e.g., ‘product’ and ‘review’).

[vk_filter_search_post_type post_types="product,review" /]

Using the shortcode to filter search results for custom post types with a custom CSS class (‘my_custom_class’) for styling.

[vk_filter_search_post_type post_types="product,review" class_name="my_custom_class" /]

Using the shortcode without any post types specified. In this case, it will default to filtering search results for posts and pages.

[vk_filter_search_post_type /]

Using the shortcode with only the class name attribute specified. This will filter search results for posts and pages, and apply the specified CSS class (‘my_custom_class’) for styling.

[vk_filter_search_post_type class_name="my_custom_class" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'vk_filter_search_post_type', array( __CLASS__, 'add_post_type_form_shortcode' ) );

Shortcode PHP function:

function add_post_type_form_shortcode( $atts, $content ) {
		$atts = shortcode_atts(
			array(
				'post_types' => 'post,page',
				'class_name'  => '',
			),
			$atts
		);

		$post_types = ! empty( $atts['post_types'] ) ? explode( ',', $atts['post_types'] ) : array();

		$options = array(
			'class_name' =>  ! empty( $atts['class_name'] ) ? $atts['class_name'] : '',
		);
		
		return VK_Filter_Search::get_post_type_form_html( $post_types, $options );
	}

Code file location:

vk-filter-search/vk-filter-search/inc/filter-search/package/class-vk-filter-search-shortcode.php

VK Filter Search [vk_filter_search_taxonomy] Shortcode

The vk-filter-search plugin shortcode allows users to add a taxonomy form to their WordPress site. It offers customization options via attributes like ‘taxonomy’ and ‘class_name’. This shortcode fetches the taxonomy form’s HTML, which can be tailored to specific categories or classes.

Shortcode: [vk_filter_search_taxonomy]

Parameters

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

  • taxonomy – Specifies the type of taxonomy for the search filter.
  • class_name – Allows for customization of the search filter styling.

Examples and Usage

Basic example – The following shortcode displays a taxonomy filter search form using the default ‘category’ taxonomy.

[vk_filter_search_taxonomy]

Advanced examples

Display a taxonomy filter search form for a custom taxonomy, such as ‘product_cat’ for WooCommerce product categories.

[vk_filter_search_taxonomy taxonomy="product_cat"]

Add a custom CSS class to the form for styling purposes. Here, we’re using a class name ‘my-custom-form’.

[vk_filter_search_taxonomy class_name="my-custom-form"]

Combine both parameters to display a taxonomy filter search form for a custom taxonomy with a custom CSS class.

[vk_filter_search_taxonomy taxonomy="product_cat" class_name="my-custom-form"]

PHP Function Code

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

Shortcode line:

add_shortcode( 'vk_filter_search_taxonomy', array( __CLASS__, 'add_taxonomy_form_shortcode' ) );

Shortcode PHP function:

function add_taxonomy_form_shortcode( $atts, $content ) {
		$atts = shortcode_atts(
			array(
				'taxonomy' => 'category',
				'class_name'  => '',
			),
			$atts
		);

		$taxonomy      = ! empty( $atts['taxonomy'] ) ? $atts['taxonomy'] : '';

		$options = array(
			'class_name' =>  ! empty( $atts['class_name'] ) ? $atts['class_name'] : '',
		);

		return VK_Filter_Search::get_taxonomy_form_html( $taxonomy, $options );
	}

Code file location:

vk-filter-search/vk-filter-search/inc/filter-search/package/class-vk-filter-search-shortcode.php

Conclusion

Now that you’ve learned how to embed the VK Filter Search 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 *