Skip to content

Commit

Permalink
Merge pull request #101 from wikitongues/main
Browse files Browse the repository at this point in the history
Deploy Typeahead Search to Staging
  • Loading branch information
FredericoAndrade authored Aug 12, 2024
2 parents 3ab9308 + 47a691d commit b866210
Show file tree
Hide file tree
Showing 16 changed files with 756 additions and 437 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Deploy to Production
on:
push:
branches:
- main
- production

env:
REMOTE_DIR: ./public_html/wp-content/themes/blankslate-child
Expand Down
185 changes: 185 additions & 0 deletions acf-json/group_668bbbba9bae8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"key": "group_668bbbba9bae8",
"title": "Typeahead-Settings",
"fields": [
{
"key": "field_668bbbbc1ad8d",
"label": "Airtable API Key",
"name": "airtable_api_key",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
},
{
"key": "field_668bbc2c1ad8e",
"label": "Airtable Base ID",
"name": "airtable_base_id",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
},
{
"key": "field_668bbc3a1ad8f",
"label": "Airtable Table Name",
"name": "airtable_table_name",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
},
{
"key": "field_668bbc461ad90",
"label": "Label Field ID",
"name": "airtable_label_field_id",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
},
{
"key": "field_668bbc511ad91",
"label": "Label Field Name",
"name": "airtable_label_field_name",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
},
{
"key": "field_668bbc5c1ad92",
"label": "Identifier Field",
"name": "airtable_identifier_field",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
},
{
"key": "field_668dc52476308",
"label": "Custom Class",
"name": "custom_class",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
},
{
"key": "field_669d8b75d8f4c",
"label": "Data Source",
"name": "data_source",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
}
],
"location": [
[
{
"param": "options_page",
"operator": "==",
"value": "acf-options"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": true,
"description": "",
"show_in_rest": 0,
"modified": 1721600905
}
63 changes: 62 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ function wt_archive_menu() {

add_action( 'init', 'wt_archive_menu' );


// add revitalization menu
function wt_revitalization_menu() {
register_nav_menu('revitalization-menu',__( 'Revitalization Menu' ));
Expand Down Expand Up @@ -214,6 +213,68 @@ function modify_page_title() {
}
add_action('wp_head', 'modify_page_title');

add_action('rest_api_init', function () {
$routes = rest_get_server()->get_routes();
error_log(print_r($routes, true));
});

function custom_register_search_endpoint() {
register_rest_route('custom/v1', '/search', array(
'methods' => 'GET',
'callback' => 'custom_search_callback',
'permission_callback' => '__return_true'
));
}

add_action('rest_api_init', 'custom_register_search_endpoint');

function custom_search_callback($request) {
$query = sanitize_text_field($request['query']);
error_log('Search query: ' . $query);

// Refine the search to include only the alternate_names field
$meta_query = array(
array(
'key' => 'alternate_names',
'value' => $query,
'compare' => 'LIKE'
)
);

$args = array(
'post_type' => 'languages',
'post_status' => 'publish',
'posts_per_page' => 100,
'meta_query' => $meta_query
);

error_log('WP_Query args: ' . print_r($args, true));

$posts = get_posts($args);

error_log('Found posts: ' . print_r($posts, true));

$results = array();
foreach ($posts as $post) {
$meta = get_post_meta($post->ID);
error_log('Post meta for ' . $post->ID . ': ' . print_r($meta, true));

$results[] = array(
'id' => $post->ID,
'label' => isset($meta['standard_name'][0]) ? $meta['standard_name'][0] : '',
'identifier' => $post->post_name,
'alternate_names' => isset($meta['alternate_names'][0]) ? $meta['alternate_names'][0] : '',
'nations_of_origin' => isset($meta['nations_of_origin'][0]) ? $meta['nations_of_origin'][0] : '',
'iso_code' => isset($meta['iso_code'][0]) ? $meta['iso_code'][0] : '',
'glottocode' => isset($meta['glottocode'][0]) ? $meta['glottocode'][0] : ''
);
}

error_log('Search results: ' . print_r($results, true));

return $results;
}

// Pagination for paged posts, Page 1, Page 2, Page 3, with Next and Previous Links, No plugin
function html5wp_pagination()
{
Expand Down
10 changes: 1 addition & 9 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,7 @@
<img class="wt_header__logo--dark <?php if ( is_front_page() ): ?>transparent-background<?php endif; ?>" src="<?php the_field('header_logo_dark', 'options'); ?>" alt="Wikitongues logo: dark color scheme">
</a>
</div>

<!-- search bar -->
<div class="wt_header__searchbar">
<i class="fa-light fa-magnifying-glass"></i>
<?php get_search_form(); ?>
</div>

<!-- navigation -->
<!-- test -->
<?php echo do_shortcode('[react_typeahead id="typeahead_nav" custom_class="nav-style" data_source="airtable"]'); ?>
<?php

// global var? define somewher else?
Expand Down
Loading

0 comments on commit b866210

Please sign in to comment.