Last active
December 2, 2024 21:43
-
-
Save wpexplorer/e95f2bc43c82a227787e8ae0d8a87432 to your computer and use it in GitHub Desktop.
Sample Filter HTML - Total WP Theme - IMPORTANT SEE EXAMPLE SHORTCODE IN THE COMMENTS!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** IMPORTANT ****/ | |
You need to make sure the AJAX script is loaded on the page which is done via PHP using the following: | |
<?php totalthemecore_call_non_static( 'Vcex\Ajax', 'enqueue_scripts' ); ?> | |
/**** SAMPLE FILTER HTML ****/ | |
@note: You can have multiple filter elements with the same target - for example if you want to have a search element that targets a filter above the grid and then the rest of the filter options to the side. | |
<div data-vcex-ajax-filter="1" data-vcex-ajax-filter-target="#YOUR_POST_CARDS_ELEMENT_UNIQUE_ID" data-vcex-ajax-filter-multiple="1" data-vcex-ajax-filter-relation="AND"> | |
SAMPLE LINK - THIS WOULD FILTER ITEMS IN "category_1" | |
<a href="#" data-vcex-type="category" data-vcex-value="category_1">Category 1</a> | |
SAMPLE NOT IN BUTTON - USE NEGATIVE TERM ID TO EXCLUDE ITEMS. | |
<button class="theme-button" data-vcex-type="post_tag" data-vcex-value="-5">Not in Tag ID 5 <span class="vcex-ajax-filter-count">(-)</span></button> | |
SAMPLE CATEGORY SELECT - for custom taxonomies simply change the data-vcex-type value to your taxonomy name. | |
<select data-vcex-type="category"> | |
<option value="">All</option> | |
<option value="category_1">Category 1</option> | |
<option value="category_2">Category 2</option> | |
<option value="category_3">Category 3</option> | |
</select> | |
SAMPLE ORDER DROPDOWN - Note: doesn't have to be a dropdown you can use links/buttons - this is just an example | |
<select data-vcex-type="order"> | |
<option value="">Default</option> | |
<option value="asc">ASC</option> | |
<option value="desc">DESC</option> | |
</select> | |
SAMPLE ORDERBY DROPDOWN | |
<select data-vcex-type="orderby"> | |
<option value="">Default</option> | |
<option value="name">Name</option> | |
<option value="date">Date</option> | |
</select> | |
SAMPLE POST TYPE DROPDOWN | |
<select data-vcex-type="post_type"> | |
<option value="">Default</option> | |
<option value="post">Post</option> | |
<option value="page">Page</option> | |
</select> | |
SAMPLE CHECKBOX | |
<input type="checkbox" id="category_1_filter" data-vcex-type="category" value="category_1"> | |
<label for="category_1_filter">Show Items in Category 1</label> | |
SAMPLE META CHECKBOX | |
<input type="checkbox" id="meta_checkbox" data-vcex-type="meta" data-vcex-key="color" value="red"> | |
<label for="meta_checkbox">Meta: Color = Red</label> | |
SAMPLE RANGE USING META VALUE | |
<input type="range" min="1" max="5" data-vcex-type="meta" data-vcex-key="wpex_post_rating" data-vcex-meta-compare="<" data-vcex-meta-type="NUMERIC" data-vcex-value="" onchange="this.nextElementSibling.value = this.value"><output>0</output> | |
SAMPLE SEARCH | |
<input type="text" data-vcex-type="search" placeholder="search items"> | |
// SAMPLE META QUERY SELECT - again, doesn't have to be a select this is just an example. | |
<select data-vcex-type="meta" data-vcex-key="color" data-vcex-meta-compare="LIKE" data-vcex-meta-type="CHAR"> | |
<option value="">Choose a Color</option> | |
<option value="red">red</option> | |
<option value="black">black</option> | |
</select> | |
SAMPLE HIDDEN FIELD | |
<input type="hidden" data-vcex-type="category" data-vcex-relation="OR" value=""> | |
SAMPLE RESET BUTTON | |
<button class="theme-button" href="#" data-vcex-type="reset">Reset</button> | |
</div> |
In Total 5.11 you can now add a "submit" button inside your filter so that the ajax filter won't run until the user clicks the submit button which can be ideal for large filters and/or filters that include search fields.
Simply add an element (button probably best) with a data-vcex-type attribute value of "submit", example:
<button class="theme-button" data-vcex-type="submit">Submit</button>
And that's it! Happy Coding ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Shortcode for a custom filter: