WordPress.org

Ready to get started?Download WordPress

Forums

Peter's Collaboration E-mails
Custom taxonomies not loading in settings (8 posts)

  1. boxcarpress
    Member
    Posted 1 year ago #

    I have three custom taxonomies on custom post types. They do not show up on the drop down menus in the admin section wecause the wp_ajax_get_post_type_taxonomies action fires before they are registered. Here is the array I shot for get_taxonomies():

    Array
    (
        [category] => category
        [post_tag] => post_tag
        [nav_menu] => nav_menu
        [link_category] => link_category
        [post_format] => post_format
    )

    Just the WordPress defaults. There are three missing taxonomies that I register in the init hook, which is how the WordPress documentation recommends. Can you delay the retrieval of the taxonomies until after init?

    http://wordpress.org/extend/plugins/peters-collaboration-e-mails/

  2. Peter
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for reporting this. At the moment I don't know how to move the loading order of the Ajax functions to be later, as there's no parameter for wp_ajax_ actions to specify when they are loaded. The solution might simply be to use an alternative way to define Ajax functions within WordPress, but I have not looked at that yet (and can't for the rest of the month, unfortunately). Any and all tips are appreciated!

  3. boxcarpress
    Member
    Posted 1 year ago #

    Finally was able to fix this. Don't ask me why, but my problem is solved by a slight change to line 1444 of peters_collaborations_emails.php. I use get_object_taxonomies:
    $taxonomies = get_object_taxonomies( $post_type, 'objects' );
    ...instead of using get_taxonomies(). The same code applies to line 1528:
    $post_type_taxonomies = get_object_taxonomies( $post_type, 'names' );
    This bug was frustrating because the code worked on our development server but not on our production server. We replicate the DB and have the same codebase, so I really can't tell you why this would be the case. One (slight) difference is the PHP version, 5.4.9 in development and 5.4.6 in production. But anyway, I hope this helps.

  4. Peter
    Member
    Plugin Author

    Posted 1 year ago #

    Thank you very much for sharing back your findings.

    That is definitely some weird behavior, but something I'll have to investigate!

  5. boxcarpress
    Member
    Posted 1 year ago #

    I'm still making this change manually for every update. Since there doesn't appear to be any drawback to using get_object_taxonomies() instead of get_taxonomies(), I wonder if you could commit this change to avoid the strange behavior for others?

  6. Peter
    Member
    Plugin Author

    Posted 1 year ago #

    I am quite close to just making the change for the next version, but I'd really get to the bottom of why this is happening.

    Both get_object_taxonomies() and get_taxonomies() are loaded in wp-includes/taxonomy.php and they both look at the $wp_taxonomies global variable. They also do a very similar comparison to return the list of relevant taxonomies.

    Is there a chance you could inspect the $wp_taxonomies global variable within both of those functions (rather than just the eventual return values)? Even if it was a problem of load order, it would seem like the global variable should be equally affected in those functions. If the global variable is the same for both functions, perhaps there is a really small difference in the way both functions parse out their results, such as a casing issue in the way the custom taxonomies were defined (as just one of many examples!).

  7. jswan2
    Member
    Posted 1 year ago #

    My similar problem (mapping tags to pages) was unfortunately not solved by just switching out get_taxomomies() for get_object_taxonomies(). I found get_taxonomies() at lines 1823 and 1907 in the newest version of this plugin. Changing get_taxonomies to get_object_taxonomies on line 1823 made built-in taxonomies for posts fail to show up, and tags for pages still didn't show up. However, doing the full edit as detailed in the 3rd post works. The plugin sends get_taxonomies arrays in the current version and that doesn't work with the get_object_taxonomies method:

    works with vanilla posts only, not pages:
    $taxonomies = get_taxonomies( array( 'object_type' => array( $post_type ) ), 'objects' );

    doesn't work with either posts or pages:
    $taxonomies = get_object_taxonomies( array( 'object_type' => array( $post_type ) ), 'objects' );

    works with both posts and pages:
    $taxonomies = get_object_taxonomies( $post_type, 'objects' );

    Hope that helps.

  8. Peter
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks a lot to both of you for investigating and confirming the fix. I've released version 1.9.2 of the plugin now, which includes the noted fix.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.