0

Can anyone clarify why this function is filtering all terms in the highlight taxonomy, but not filtering for the subscribe-win term?

Neither $term->term_id or $term->slug are working.

I don't get any errors and it is only filtering highlight - and not other taxonomies.

Thanks!

    add_filter( 'term_link', 'slick_term_to_page', 10, 3 );

    function slick_term_to_page( $url, $term, $taxonomy ) {

        if ( $taxonomy != 'highlight' && $term->term_id != 42 ) :
        // if ( $taxonomy != 'highlight' && $term->slug != 'subscribe-win' ) :  

            return $url;

        else :

            $url = home_url( '/win' ); 
            return $url;

        endif;
    }
  • The taxonomy of term 'subscribe-win' is 'highlight'? – Lucas Vendramini Jun 19 at 20:30
  • highlight is the taxonomy. subscribe-win is a term in highlight. 42 is the term_id.... this filter should isolate the 42 but is not ... it's applying to every term in highlight. – ljburton Jun 19 at 20:42
  • Are you sure the term id of 'subscribe-win' is 42? Can you paste the var_dump of term object? Do you know the content of $url variable? What you want to achieve? – Lucas Vendramini Jun 19 at 20:47
  • 1
    I think you dont need to specify the taxonomy, term id is unique for all terms of all taxonomies. – Lucas Vendramini Jun 19 at 20:55
  • As followup, goal is anytime user clicks the susbscribe-win term they are taken to the win page - which is using a custom page template - and not an archive template ... Why, you ask? Because I want page features like comments and social sharing ... Thanks again! – ljburton Jun 19 at 21:11
1

Thanks Lucas! I found this code as an example in several places ... still interesting that the && doesn't work ... but this does :)

    add_filter( 'term_link', 'slick_term_to_page', 10, 3 );

    function slick_term_to_page( $url, $term, $taxonomy ) {

        if ( $term->term_id != 42 ) :
        // if ( $taxonomy != 'highlight' && $term->term_id != 42 ) :    
        // if ( $taxonomy != 'highlight' && $term->slug != 'subscribe-win' ) :  

            return $url;

        else :

            $url = home_url( '/win' ); 
            return $url;

        endif;
    }
  • Glad to help you! Thinking about this, if you deny that the taxonomy is 'highlight' you are denying the other terms of the taxonomy 'hightlight' should have the url '/win', not only the term that are only 42. – Lucas Vendramini Jun 19 at 21:20
  • Still makes no sense ... with both conditions, all terms in highlight were getting the win URL ... I read it as "if not in highlight taxonomy and not term 42" ... Of course the single condition is fine by me, but the double conditions should have worked ... some things are meant to be mysteries :) – ljburton Jun 19 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.