Forums › Forums › Search & Filter Pro › Cannot Add Custom Taxonomy to Search
- This topic has 8 replies, 2 voices, and was last updated 9 years, 11 months ago by Ross.
-
Anonymous(Private) January 12, 2015 at 6:47 pm #10152
Hi, when I add a search item for my custom taxonomies in the search form UI and display the search form on my website the following error occurs:
Notice: Trying to get property of non-object in C:\xampp\htdocs\wordpress\wp-content\plugins\search-filter-pro\public\includes\class-search-filter-display-shortcode.php on line 705
Is there something I need to adjust in my taxonomy registration?
Ross Moderator(Private) January 12, 2015 at 7:46 pm #10157Hey David
How are you defining your taxonomies? I believe you must also setup the different labels for your taxonomies –
A quick look at line 705 shows:
$values['all_items_label'] = $taxonomydata->labels->all_items;
It is trying to read the label “all_items” in your taxonomy but it looks like it does not exists.
If you are creating your taxonomies with code please see this as an example with settings labels – http://www.smashingmagazine.com/2012/01/04/create-custom-taxonomies-wordpress/
Thanks
Anonymous(Private) January 12, 2015 at 8:20 pm #10161Thanks for the quick reply. Below is the taxonomy declaration I am using. The all_items field in the labels array is declared as expected but it seems the filter plugin cannot access it:
$labels = array( 'name' => _x( 'Locations', 'Taxonomy General Name', 'text_domain' ), 'singular_name' => _x( 'Location', 'Taxonomy Singular Name', 'text_domain' ), 'menu_name' => __( 'Locations', 'text_domain' ), 'all_items' => __( 'All locations', 'text_domain' ), 'parent_item' => __( 'Parent Location', 'text_domain' ), 'parent_item_colon' => __( 'Parent Location:', 'text_domain' ), 'new_item_name' => __( 'New Location Name', 'text_domain' ), 'add_new_item' => __( 'Add New Location', 'text_domain' ), 'edit_item' => __( 'Edit Location', 'text_domain' ), 'update_item' => __( 'Update Location', 'text_domain' ), 'separate_items_with_commas' => __( 'Separate locations with commas', 'text_domain' ), 'search_items' => __( 'Search locations', 'text_domain' ), 'add_or_remove_items' => __( 'Add or remove locations', 'text_domain' ), 'choose_from_most_used' => __( 'Choose from the most used locations', 'text_domain' ), 'not_found' => __( 'Location Not Found', 'text_domain' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); register_taxonomy( 'locations', array( 'spaces' ), $args );
I also used the exact same custom taxonomy sample code provided in the link you sent in your reply adjusting only the taxonomy name and $object_type parameter for my custom post type and I still get the same error from the filter plugin.
Anonymous(Private) January 12, 2015 at 8:50 pm #10163The strange thing is that it the taxonomy is being registered correctly because I can see it in the WordPress menu and in my plugin. Does it make a difference to the filter plugin that the taxonomy is being registered via the init hook?
add_action( 'init', array($this, 'location_taxonomy'), 0 );
Ross Moderator(Private) January 13, 2015 at 1:55 pm #10189Hmmm
I would try without the priority argument
So
add_action( 'init', array($this, 'location_taxonomy'), 0 );
Should become
add_action( 'init', array($this, 'location_taxonomy'));
Although logically it makes sense to give it a higher priority…
I’m sure you’ve done it from your research, but can you try copying and pasting the below directly into your themes functions.php (at the bottom) and seeing if there is now a writers taxonomy for a post?
// hook into the init action and call create_book_taxonomies when it fires add_action( 'init', 'create_book_taxonomies', 0 ); // create two taxonomies, genres and writers for the post type "post" function create_book_taxonomies() { // Add new taxonomy, make it hierarchical (like categories) // Add new taxonomy, NOT hierarchical (like tags) $labels = array( 'name' => _x( 'Writers', 'taxonomy general name' ), 'singular_name' => _x( 'Writer', 'taxonomy singular name' ), 'search_items' => __( 'Search Writers' ), 'popular_items' => __( 'Popular Writers' ), 'all_items' => __( 'All Writers' ), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __( 'Edit Writer' ), 'update_item' => __( 'Update Writer' ), 'add_new_item' => __( 'Add New Writer' ), 'new_item_name' => __( 'New Writer Name' ), 'separate_items_with_commas' => __( 'Separate writers with commas' ), 'add_or_remove_items' => __( 'Add or remove writers' ), 'choose_from_most_used' => __( 'Choose from the most used writers' ), 'not_found' => __( 'No writers found.' ), 'menu_name' => __( 'Writers' ), ); $args = array( 'hierarchical' => false, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'rewrite' => array( 'slug' => 'writer' ), ); register_taxonomy( 'writer', 'post', $args ); }
Thanks
Anonymous(Private) January 13, 2015 at 6:25 pm #10213Changing the priority still results in the same error.
When adding your code to the theme’s function.php file I can use it in the filter plugin without error. I also went ahead and tested my own custom taxonomies in the functions.php file and they also work when registered in this file. Any idea why the filter plugin is ok when my custom taxonomies are registered in the functions.php file instead of my own custom plugin?
Ross Moderator(Private) January 13, 2015 at 8:11 pm #10223Hey David – I’m afraid I’m not sure about that – it might be where you are registering your filter
If for example I have a hook on init, and in that hook I also add
add_action( 'init', array($this, 'location_taxonomy'));
Then there is no way this can be run first – but it might get added after…
Basically, be careful of where add_action is called, it might registering the action later…
Does that make sense?
Thanks
Anonymous(Private) January 14, 2015 at 6:23 am #10234Hi Ross, thanks for your help. It caused me to think about when my functions for registering the taxonomies and custom post types were being done. I moved these functions outside of my plugin class block and noticed that your filter plugin was working as expected. And then I realized that I was previously only registering the taxonomies and post types inside my plugin class and the plugin was only being executed on the admin side because I was only instantiating the class within an
is_admin
block in my code.Thanks again for your support! You can mark this thread as being resolved.
-
AuthorPosts