• Resolved halukkuruoglu

    (@halukkuruoglu)


    Hi there,
    I’m using the plugin on my site and evertyhting works smoothly.
    There is a custom page (single-book.php) where I want that custom terms (sidetheme) not to be sorted, I want them to appear in the order that they are inserted to the post.
    I tried:
    add_filter( ‘customtaxorder_exclude_taxonomies’, ‘add_taxonomy_to_customtaxorder_exclude_taxonomies’);
    function add_taxonomy_to_customtaxorder_exclude_taxonomies( $taxonomies ) {
    $taxonomies = array();
    if ( is_page_template( ‘single-book.php’ ) ) {
    $taxonomies[] = ‘sidetheme’;
    return $taxonomies;
    }
    }
    but I got this error:
    Warning: in_array() expects parameter 2 to be array, null given in /var/www/vhosts/gunisigiyou.com/httpdocs/wp-content/plugins/custom-taxonomy-order-ne/customtaxorder.php on line 377
    and the terms are still sorted.
    Can you please help?
    Thank you,
    Haluk

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Marcel Pol

    (@mpol)

    Hi Haluk,
    I think it will be best to disable the filters on that post or page.

    Code like this might do it:

    function my_remove_term_sorting() {
        if ( is_single() && is_page('127') ) {
            remove_filter( 'wp_get_object_terms', 'customtaxorder_wp_get_object_terms_order_filter' );
            remove_filter( 'get_terms', 'customtaxorder_wp_get_object_terms_order_filter');
            remove_filter( 'get_the_terms', 'customtaxorder_wp_get_object_terms_order_filter' );
            remove_filter( 'tag_cloud_sort', 'customtaxorder_wp_get_object_terms_order_filter' );
            remove_filter( 'term_query_results', 'customtaxorder_wp_get_object_terms_order_filter' );
        }
    }
    add_action('plugins_loaded', 'my_remove_term_sorting');

    The 127 should be replaced by the ID of that page.
    Does this help?

    Thread Starter halukkuruoglu

    (@halukkuruoglu)

    Thanks Marcel, I’ll give a try and get back to you

    Thread Starter halukkuruoglu

    (@halukkuruoglu)

    Hi Marcel,

    Sorry it didn’t work.
    I also tried to add:
    remove_filter( ‘wp_get_post_terms’, ‘customtaxorder_wp_get_object_terms_order_filter’ );
    into your function (because it is the wp_get_post_terms which is used to call on the page) but I still get the list of the terms sorted.

    This is the code where I call the terms in single-book.php:
    $terms4 = wp_get_post_terms( $post->ID, ‘sidetheme’ );
    $my_sidethemes = ‘<br />’;
    foreach ( $terms4 as $term4 ) {
    $term4 = sanitize_term( $term4, ‘sidetheme’ );
    $term4_link = get_term_link( $term4, ‘sidetheme’ );
    if ( is_wp_error( $term4_link ) ) {
    continue;
    }
    $my_sidethemes .= ‘‘ . $term4->name . ‘ &bullet; ‘;
    }
    What am I missing?

    Plugin Author Marcel Pol

    (@mpol)

    When you remove the check for is_single and is_page, does it work then? Just to test if that custom function is even run.

    There is also the plugin Query Monitor, that might give some insight into which hooks are run.

    Thread Starter halukkuruoglu

    (@halukkuruoglu)

    You’re right, when I comment if lines nothing changes, so the function does not run at all I suppose.
    I’ll give a try to the Query Monitor
    Thanks

    Plugin Author Marcel Pol

    (@mpol)

    function my_remove_term_sorting() {
        //if ( is_singular() ) { // && get_the_ID() == 11551 ) {
           remove_filter( 'wp_get_object_terms', 'customtaxorder_wp_get_object_terms_order_filter' );
           remove_filter( 'get_terms', 'customtaxorder_wp_get_object_terms_order_filter');
           remove_filter( 'get_the_terms', 'customtaxorder_wp_get_object_terms_order_filter' );
           remove_filter( 'tag_cloud_sort', 'customtaxorder_wp_get_object_terms_order_filter' );
           remove_filter( 'term_query_results', 'customtaxorder_wp_get_object_terms_order_filter' );
           remove_filter( 'get_the_categories', 'customtaxorder_order_categories' );
        //}
    }
    add_action('wp_loaded', 'my_remove_term_sorting');

    This code works, but it is not what you want.
    Adding the action to ‘wp’ hook will already have sorted the terms, so removing the filters makes no sense.
    But running it in ‘wp_loaded’, there is no post object yet, so you cannot run the template functions to test for the post ID.

    Is this something you can move further yourself? I am not sure what a good way forward would be even.

    By the way, in Query Monitor, you can see that with this code, it is not running the ‘customtaxorder_terms_ordered’ action. That is what you want to have happen.

    Plugin Author Marcel Pol

    (@mpol)

    Plugin Author Marcel Pol

    (@mpol)

    I would think in the ‘pre_get_posts’ hook, you could do some magic.

    Thread Starter halukkuruoglu

    (@halukkuruoglu)

    Thank you, you can close this topic

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How not to sort a term in a particular page’ is closed to new replies.