skip to Main Content

I am using this rewrite rule function but it does not work in child theme. It seems not going inside callback function at all.

function add_rewrite_rules($aRules) {
    $term_obj = get_queried_object();
    //print_r($term_obj);
    if(isset($term_obj->term_id) && $term_obj->term_id!=""){
        $aNewRules = array('casselberry-antique-white/([^/]+)/?$' => 'templates/product-list-template.php?manufacturer_id=$matches[1]');
        $aRules = $aNewRules + $aRules;
        return $aRules;
  }
  else{
    return $aRules;
  }

}

2

Answers


  1. Instead of isset try using property_exists

    see: https://www.php.net/manual/en/function.property-exists.php

    Login or Signup to reply.
  2. When you call add_rewrite_rules function?

    You need init hook, add_rewrite_rule is a function core WordPress see link

    add_action('init', function() {
        add_rewrite_rule(
            'casselberry-antique-white/([^/]+)/?$',
            'templates/product-list-template.php?manufacturer_id=$matches[1]',
            'top'
        );
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search