最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

term_link filter rewrite link only applying half of condition?

programmeradmin1浏览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;
    }

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;
    }
Share Improve this question asked Jun 19, 2019 at 20:20 user145691user145691 5
  • The taxonomy of term 'subscribe-win' is 'highlight'? – Lucas Vendramini Commented Jun 19, 2019 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. – user145691 Commented Jun 19, 2019 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 Commented Jun 19, 2019 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 Commented Jun 19, 2019 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! – user145691 Commented Jun 19, 2019 at 21:11
Add a comment  | 

1 Answer 1

Reset to default 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;
    }
发布评论

评论列表(0)

  1. 暂无评论