Forked from codersaiful/taxonomy_by_search_keyword.php
Last active
August 10, 2020 04:36
-
-
Save autocircled/ae632518c9efc90389e64608a7e5b285 to your computer and use it in GitHub Desktop.
This file contains 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
if( !function_exists( 'load_terms_by_ajax' ) ) { | |
function load_terms_by_ajax(){ | |
$ky = isset( $_GET['q'] ) && !empty( $_GET['q'] ) ? $_GET['q'] : ''; | |
$term_name = isset( $_GET['key'] ) && !empty( $_GET['key'] ) ? $_GET['key'] : ''; | |
$taxonomy_sarch_args = array('hide_empty' => true,'orderby' => 'name','order' => 'ASC', 'name__like' => $ky, ); | |
$tax_obj = get_terms( $term_name, $taxonomy_sarch_args ); | |
$arr['results'] = array(); | |
if( count( $tax_obj ) > 0 ){ | |
foreach( $tax_obj as $item ){ | |
$arr['results'][] = array( | |
'id' => $item->term_id, | |
'text' => $item->name, | |
); | |
} | |
} | |
echo json_encode($arr); | |
die(); | |
} | |
} | |
add_action( 'wp_ajax_load_terms_by_ajax', 'load_terms_by_ajax' ); | |
add_action( 'wp_ajax_nopriv_load_terms_by_ajax', 'load_terms_by_ajax' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment