Forums › Forums › Search & Filter Pro › Multisite Twenty Twenty Child theme
Tagged: multisite, twentytwenty
- This topic has 11 replies, 2 voices, and was last updated 4 years, 3 months ago by Trevor.
-
Anonymous(Private) September 8, 2020 at 9:43 am #258691
Hello – Having major issues with my multisite installation not working with Search & Filter Pro. Here are the notes I have:
– The plugin is currently not network activated, only activated within the subsite.
– All subsites within the multisite are child themes of Twenty Twenty.
– Displaying results as a shortcode in the hardcoded template.
– I attempted to add custom post type + custom taxonomy to the functions.php file. However, the search form either doesn’t show up or is repeated several times down the page along with the results. Very inconsistent.functions.php
/* ---------------------------- * Creating a function to create our ALUMNI CPT ---------------------------- */ function custom_post_type() { // Set UI labels for Custom Post Type $labels = array( 'name' => _x( 'Alumni', 'Post Type General Name', 'twentytwenty' ), 'singular_name' => _x( 'Alumnus', 'Post Type Singular Name', 'twentytwenty' ), 'menu_name' => __( 'Alumni', 'twentytwenty' ), 'parent_item_colon' => __( 'Parent Alumnus', 'twentytwenty' ), 'all_items' => __( 'All Alumni', 'twentytwenty' ), 'view_item' => __( 'View Alumnus', 'twentytwenty' ), 'add_new_item' => __( 'Add New Alumnus', 'twentytwenty' ), 'add_new' => __( 'Add New', 'twentytwenty' ), 'edit_item' => __( 'Edit Alumnus', 'twentytwenty' ), 'update_item' => __( 'Update Alumnus', 'twentytwenty' ), 'search_items' => __( 'Search Alumnus', 'twentytwenty' ), 'not_found' => __( 'Not Found', 'twentytwenty' ), 'not_found_in_trash' => __( 'Not found in Trash', 'twentytwenty' ), ); // Set other options for Custom Post Type $args = array( 'label' => __( 'alumni', 'twentytwenty' ), 'description' => __( 'Alumnus information', 'twentytwenty' ), 'labels' => $labels, // Features this CPT supports in Post Editor 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields' ), /* A hierarchical CPT is like Pages and can have * Parent and child items. A non-hierarchical CPT * is like Posts. */ 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', 'show_in_rest' => true, ); // Registering your Custom Post Type register_post_type( 'alumni', $args ); /* Hook into the 'init' action so that the function * Containing our post type registration is not * unnecessarily executed. */ add_action( 'init', 'custom_post_type', 0 ); } /* ---------------------------- * Registering Taxonomies for ALUMNI CPT ---------------------------- */ // Register Sport Taxonomy $labels_sport = array( 'name' => _x( 'Sport', 'taxonomy general name' ), 'singular_name' => _x( 'Sport', 'taxonomy singular name' ), 'search_items' => __( 'Search Sport' ), 'all_items' => __( 'All Sports' ), 'parent_item' => __( 'Parent Sport' ), 'parent_item_colon' => __( 'Parent Sport:' ), 'edit_item' => __( 'Edit Sport' ), 'update_item' => __( 'Update Sport' ), 'add_new_item' => __( 'Add New Sport' ), 'new_item_name' => __( 'New Sport Name' ), ); register_taxonomy( 'sport', // The name of the custom taxonomy array( 'alumni' ), // Associate it with our custom post type array( 'hierarchical' => true, 'rewrite' => array( 'slug' => 'sport', // Use "topic" instead of "topics" in permalinks 'hierarchical' => true // Allows sub-topics to appear in permalinks ), 'labels' => $labels_sport ) ); // Register Region Taxonomy $labels_region = array( 'name' => _x( 'Region', 'taxonomy general name' ), 'singular_name' => _x( 'Region', 'taxonomy singular name' ), 'search_items' => __( 'Search Regions' ), 'all_items' => __( 'All Regions' ), 'parent_item' => __( 'Parent Region' ), 'parent_item_colon' => __( 'Parent Region:' ), 'edit_item' => __( 'Edit Region' ), 'update_item' => __( 'Update Region' ), 'add_new_item' => __( 'Add New Region' ), 'new_item_name' => __( 'New Region Name' ), ); register_taxonomy( 'region', // The name of the custom taxonomy array( 'alumni' ), // Associate it with our custom post type array( 'hierarchical' => true, 'rewrite' => array( 'slug' => 'region', // Use "topic" instead of "topics" in permalinks 'hierarchical' => true // Allows sub-topics to appear in permalinks ), 'labels' => $labels_region ) ); // Register Year Taxonomy $labels_year = array( 'name' => _x( 'Year', 'taxonomy general name' ), 'singular_name' => _x( 'Year', 'taxonomy singular name' ), 'search_items' => __( 'Search Years' ), 'all_items' => __( 'All Years' ), 'parent_item' => __( 'Parent Year' ), 'parent_item_colon' => __( 'Parent Year:' ), 'edit_item' => __( 'Edit Year' ), 'update_item' => __( 'Update Year' ), 'add_new_item' => __( 'Add New Year' ), 'new_item_name' => __( 'New Year Name' ), ); register_taxonomy( 'year', // The name of the custom taxonomy array( 'alumni' ), // Associate it with our custom post type array( 'hierarchical' => true, 'rewrite' => array( 'slug' => 'year', // Use "topic" instead of "topics" in permalinks 'hierarchical' => true // Allows sub-topics to appear in permalinks ), 'labels' => $labels_year ) ); /* ---------------------------- * Set a filter on admin page to filter resources by new taxonomies for ALUMNI CPT ---------------------------- */ /* -- SPORT filter -- */ function restrict_alumni_by_sport() { global $typenow; $post_type = 'alumni'; // change HERE $taxonomy = 'sport'; // change HERE if ($typenow == $post_type) { $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : ''; $info_taxonomy = get_taxonomy($taxonomy); wp_dropdown_categories(array( 'show_option_all' => __("Show All {$info_taxonomy->label}"), 'taxonomy' => $taxonomy, 'name' => $taxonomy, 'orderby' => 'name', 'selected' => $selected, 'show_count' => true, 'hide_empty' => true, )); }; } add_action('restrict_manage_posts', 'restrict_alumni_by_sport'); function convert_sport_to_term_in_query($query) { global $pagenow; $post_type = 'alumni'; // change HERE $taxonomy = 'sport'; // change HERE $q_vars = &$query->query_vars; if ($pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0) { $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy); $q_vars[$taxonomy] = $term->slug; } } add_filter('parse_query', 'convert_sport_to_term_in_query'); /* -- REGION filter -- */ function restrict_alumni_by_region() { global $typenow; $post_type = 'alumni'; // change HERE $taxonomy = 'region'; // change HERE if ($typenow == $post_type) { $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : ''; $info_taxonomy = get_taxonomy($taxonomy); wp_dropdown_categories(array( 'show_option_all' => __("Show All {$info_taxonomy->label}"), 'taxonomy' => $taxonomy, 'name' => $taxonomy, 'orderby' => 'name', 'selected' => $selected, 'show_count' => true, 'hide_empty' => true, )); }; } add_action('restrict_manage_posts', 'restrict_alumni_by_region'); function convert_region_to_term_in_query($query) { global $pagenow; $post_type = 'alumni'; // change HERE $taxonomy = 'region'; // change HERE $q_vars = &$query->query_vars; if ($pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0) { $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy); $q_vars[$taxonomy] = $term->slug; } } add_filter('parse_query', 'convert_region_to_term_in_query'); /* -- YEAR filter -- */ function restrict_alumni_by_year() { global $typenow; $post_type = 'alumni'; // change HERE $taxonomy = 'year'; // change HERE if ($typenow == $post_type) { $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : ''; $info_taxonomy = get_taxonomy($taxonomy); wp_dropdown_categories(array( 'show_option_all' => __("Show All {$info_taxonomy->label}"), 'taxonomy' => $taxonomy, 'name' => $taxonomy, 'orderby' => 'name', 'selected' => $selected, 'show_count' => true, 'hide_empty' => true, )); }; } add_action('restrict_manage_posts', 'restrict_alumni_by_year'); function convert_year_to_term_in_query($query) { global $pagenow; $post_type = 'alumni'; // change HERE $taxonomy = 'year'; // change HERE $q_vars = &$query->query_vars; if ($pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0) { $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy); $q_vars[$taxonomy] = $term->slug; } } add_filter('parse_query', 'convert_year_to_term_in_query');
Need help please!
Trevor(Private) September 8, 2020 at 10:02 am #258693Are you saying that the form does not work with the Custom Post Type and the Custom Taxonomy you have made, or that it does not appear correctly on a page, or both?
I assume that the Custom Post Type and the Custom Taxonomy are made just within the one subsite in that subsite’s child theme functions.php file?
And that any template you have modified to add the form and/or results is also just within that subsite child theme folder?
Anonymous(Private) September 8, 2020 at 10:08 am #258695Thanks for the quick response! It is super appreciated.
Yes, from what I am seeing, the form does not work with the Custom Post Type and Custom Taxonomy in the functions.php file. However, as you can probably imagine, that code is critical to the search. I also tried using the below CPT format but to no avail either:
add_action( 'init', 'create_user_story_tax' ); function create_user_story_tax() { /* Create Genre Taxonomy */ $args = array( 'label' => __( 'Genre' ), 'rewrite' => array( 'slug' => 'genre' ), 'hierarchical' => true, ) register_taxonomy( 'genre', 'user-story', $args ); /* Create Story Type Taxonomy */ $args = array( 'label' => __( 'Story Type' ), 'rewrite' => array( 'slug' => 'story-type' ), 'hierarchical' => true, ) register_taxonomy( 'story-type', 'user-story', $args );
Anonymous(Private) September 8, 2020 at 10:09 am #258697Yes, that CPT and custom taxonomy are created only within the /subsite-1 theme. There are 3 subsites total in the multisite installation:
http://domain.com
http://domain.com/subsite-1
http://domain.com/subsite-2 -
AuthorPosts