Last active
January 25, 2020 00:20
Revisions
-
itzikbenh revised this gist
Aug 5, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ <?php //NOTE - function.php expects it to be inside an api folder. //I'm returning the post title inside of a link. Do it however you wish and adjust accordingly //in the typeahead.js file function get_companies(WP_REST_Request $request) -
itzikbenh revised this gist
Aug 5, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ <?php //I'm returning the post title inside of a link. Do it however you wish and adjust accordingly //in the typeahead.js file function get_companies(WP_REST_Request $request) { -
itzikbenh revised this gist
Aug 5, 2016 . 2 changed files with 3 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,9 +12,8 @@ function get_companies(WP_REST_Request $request) foreach( $companies as $company ) { $permalink = get_post_permalink($company->ID); $name = "<a class='company-link' href=$permalink>$company->post_title</a>"; array_push($companies_names, $name); } 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 charactersOriginal file line number Diff line number Diff line change @@ -6,10 +6,8 @@ $('.typeahead').typeahead({ return item; }, updater: function (item) { //redirect user on click window.location.href = $(item).attr("href"); }, source: function (query, process) { return $.get(theme_data.site_url + 'wp-json/companies/v1/companies', { q: query }, function (data) { -
itzikbenh revised this gist
Aug 4, 2016 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,6 @@ //in the typeahead.js file function get_companies(WP_REST_Request $request) { $companies = query_posts( array( "post_type" => "company", "s" => $request['q'] -
itzikbenh renamed this gist
Aug 3, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
itzikbenh revised this gist
Aug 3, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,8 @@ function theme_js() //Download from here - https://github.com/bassjobsen/Bootstrap-3-Typeahead wp_enqueue_script( 'typehead__boostrap_js', get_template_directory_uri() . '/js/typeahead-bootstrap.js', array('jquery'), '', true ); wp_enqueue_script( 'theme_js', get_template_directory_uri() . '/js/theme.js', array('jquery', 'jquery-ui-datepicker'), '', true ); wp_localize_script( 'theme_js', 'theme_data', array('site_url' => network_site_url( '/' )) ); } add_action( 'wp_enqueue_scripts', 'theme_js' ); -
itzikbenh revised this gist
Aug 3, 2016 . No changes.There are no files selected for viewing
-
itzikbenh created this gist
Aug 3, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ function theme_styles() { wp_enqueue_style( 'boostrap_css', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css' ); wp_enqueue_style( 'theme_css', get_template_directory_uri() . '/css/theme.css' ); } add_action( 'wp_enqueue_scripts', 'theme_styles' ); function theme_js() { wp_enqueue_script( 'bootstrap_js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js', array('jquery'), '', true ); //Download from here - https://github.com/bassjobsen/Bootstrap-3-Typeahead wp_enqueue_script( 'typehead__boostrap_js', get_template_directory_uri() . '/js/typeahead-bootstrap.js', array('jquery'), '', true ); wp_enqueue_script( 'theme_js', get_template_directory_uri() . '/js/theme.js', array('jquery', 'jquery-ui-datepicker'), '', true ); } add_action( 'wp_enqueue_scripts', 'theme_js' ); include( get_template_directory() . '/api/process-get-companies.php' ); //Endpoint for getting companies function water_endpoints() { register_rest_route('companies/v1', '/companies/', array( 'methods' => 'GET', 'callback' => 'get_companies' )); } add_action( 'rest_api_init', 'water_endpoints' ); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ //I will leave the rest for you. <input class="typeahead form-control" type="text" placeholder="Search..." data-provide="typeahead"> 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ <?php //I'm returning the post title inside of a link and also the thumbnail. Do it however you wish and adjust accordingly //in the typeahead.js file function get_companies(WP_REST_Request $request) { //return $request['q']; $companies = query_posts( array( "post_type" => "company", "s" => $request['q'] ) ); $companies_names = []; foreach( $companies as $company ) { $company_logo = get_the_post_thumbnail($company->ID); $permalink = get_post_permalink($company->ID); $name = "$company_logo<a class='company-link' href=$permalink>$company->post_title</a>"; array_push($companies_names, $name); } return $companies_names; } ?> 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ (function($) { $('.typeahead').typeahead({ //So we can render HTML inside the list highlighter: function(item) { return item; }, updater: function (item) { //This is how I dig out the href attribute. If you change the PHP code then it will probably break this //so make sure to adjust it. var url = $(item)[1]; window.location.href = $(url).attr("href"); }, source: function (query, process) { return $.get(theme_data.site_url + 'wp-json/companies/v1/companies', { q: query }, function (data) { return process(data); }); } }); })(jQuery);