Skip to main content
added 22 characters in body
Source Link
nmr
  • 4.5k
  • 2
  • 17
  • 25

In the link you attached, you have everything you need. You should:

  • add query variable (e.g operators_actv),
  • add rewrite rule that sets this variable (operators_actv),
  • use the template_include action hook to load custom template if query variable operators_actv is set.

Code:

add_filter( 'query_vars', 'se332319_custom_query_vars' );
add_filter( 'template_include', 'se332319_custom_template', 50 );
add_action( 'generate_rewrite_rules', 'se332319_resources_cpt_generating_rule' );

function se332319_resources_cpt_generating_rule( $wp_rewrite ) 
{
    $rules = [
        'operators/([^/]+)/?$' => 'index.php?operators_actv=$matches[1]'operators_actv=$matches[1]&activities=$matches[1]'
    ];
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;

    return $wp_rewrite;
}

function se332319_custom_query_vars( $query_vars )
{
    array_push( $query_vars, 'operators_actv' );
    return $query_vars;
}

function se332319_custom_template( $template )
{
    $qv = get_query_var('operators_actv', null);
    if ( $qv !== null && term_exists($qv, 'activites') !== null ) {

        // use "get_stylesheet_directory()" or "get_template_directory()"
        // if template file is in theme directory 
        $template =  dirname(__FILE__) . '/se332319_custom_template.php';
    }
    return $template;
}

Don't forget to refresh permalinks. Click Save in Dashboars -> Settings -> Permalinks or do it from code with flush_rewrite_rules() (how to recreate rewrite rules).

In the link you attached, you have everything you need. You should:

  • add query variable (e.g operators_actv),
  • add rewrite rule that sets this variable (operators_actv),
  • use the template_include action hook to load custom template if query variable operators_actv is set.

Code:

add_filter( 'query_vars', 'se332319_custom_query_vars' );
add_filter( 'template_include', 'se332319_custom_template', 50 );
add_action( 'generate_rewrite_rules', 'se332319_resources_cpt_generating_rule' );

function se332319_resources_cpt_generating_rule( $wp_rewrite ) 
{
    $rules = [
        'operators/([^/]+)/?$' => 'index.php?operators_actv=$matches[1]'
    ];
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;

    return $wp_rewrite;
}

function se332319_custom_query_vars( $query_vars )
{
    array_push( $query_vars, 'operators_actv' );
    return $query_vars;
}

function se332319_custom_template( $template )
{
    $qv = get_query_var('operators_actv', null);
    if ( $qv !== null && term_exists($qv, 'activites') !== null ) {

        // use "get_stylesheet_directory()" or "get_template_directory()"
        // if template file is in theme directory 
        $template =  dirname(__FILE__) . '/se332319_custom_template.php';
    }
    return $template;
}

Don't forget to refresh permalinks. Click Save in Dashboars -> Settings -> Permalinks or do it from code with flush_rewrite_rules() (how to recreate rewrite rules).

In the link you attached, you have everything you need. You should:

  • add query variable (e.g operators_actv),
  • add rewrite rule that sets this variable (operators_actv),
  • use the template_include action hook to load custom template if query variable operators_actv is set.

Code:

add_filter( 'query_vars', 'se332319_custom_query_vars' );
add_filter( 'template_include', 'se332319_custom_template', 50 );
add_action( 'generate_rewrite_rules', 'se332319_resources_cpt_generating_rule' );

function se332319_resources_cpt_generating_rule( $wp_rewrite ) 
{
    $rules = [
        'operators/([^/]+)/?$' => 'index.php?operators_actv=$matches[1]&activities=$matches[1]'
    ];
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;

    return $wp_rewrite;
}

function se332319_custom_query_vars( $query_vars )
{
    array_push( $query_vars, 'operators_actv' );
    return $query_vars;
}

function se332319_custom_template( $template )
{
    $qv = get_query_var('operators_actv', null);
    if ( $qv !== null && term_exists($qv, 'activites') !== null ) {

        // use "get_stylesheet_directory()" or "get_template_directory()"
        // if template file is in theme directory 
        $template =  dirname(__FILE__) . '/se332319_custom_template.php';
    }
    return $template;
}

Don't forget to refresh permalinks. Click Save in Dashboars -> Settings -> Permalinks or do it from code with flush_rewrite_rules() (how to recreate rewrite rules).

deleted 169 characters in body
Source Link
nmr
  • 4.5k
  • 2
  • 17
  • 25

In the link you attached, you have everything you need. You should:

  • add query variable (e.g operators_actv),
  • add rewrite rule that sets this variable (operators_actv),
  • use the template_include action hook to load custom template if query variable operators_actv is set.

Code:

add_filter( 'query_vars', 'se332319_custom_query_vars' );
add_filter( 'template_include', 'se332319_custom_template', 50 );
add_action( 'generate_rewrite_rules', 'se332319_resources_cpt_generating_rule' );

function se332319_resources_cpt_generating_rule( $wp_rewrite ) 
{
    $rules = array();
    $terms = get_terms( array(
        'taxonomy' => 'activites',
        'hide_empty' => false,
    ) );
[
    $post_type = 'operator';
    foreach 'operators/($terms as $term) {
        $rules['operators[^/' . $term->slug . ']+)/?$']$' ==> 'index.php?operators_actv='.$term->slug;            operators_actv=$matches[1]'
    }];
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;

    return $wp_rewrite;
}

function se332319_custom_query_vars( $query_vars )
{
    array_push( $query_vars, 'operators_actv' );
    return $query_vars;
}

function se332319_custom_template( $template )
{
    if$qv (= get_query_var('operators_actv', null);
    if ( $qv !== null && term_exists($qv, 'activites') !== null ) { 

        // use "get_stylesheet_directory()" or "get_template_directory()"
        // if template file is in theme directory 
        $template =  dirname(__FILE__) . '/se332319_custom_template.php';
    }
    return $template;
}

Don't forget to refresh permalinks. Click Save in Dashboars -> Settings -> Permalinks or do it from code with flush_rewrite_rules() (how to recreate rewrite rules).

In the link you attached, you have everything you need. You should:

  • add query variable (e.g operators_actv),
  • add rewrite rule that sets this variable (operators_actv),
  • use the template_include action hook to load custom template if query variable operators_actv is set.

Code:

add_filter( 'query_vars', 'se332319_custom_query_vars' );
add_filter( 'template_include', 'se332319_custom_template', 50 );
add_action( 'generate_rewrite_rules', 'se332319_resources_cpt_generating_rule' );

function se332319_resources_cpt_generating_rule( $wp_rewrite ) 
{
    $rules = array();
    $terms = get_terms( array(
        'taxonomy' => 'activites',
        'hide_empty' => false,
    ) );

    $post_type = 'operator';
    foreach ($terms as $term) {
        $rules['operators/' . $term->slug . '/?$'] = 'index.php?operators_actv='.$term->slug;            
    }
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;

    return $wp_rewrite;
}

function se332319_custom_query_vars( $query_vars )
{
    array_push( $query_vars, 'operators_actv' );
    return $query_vars;
}

function se332319_custom_template( $template )
{
    if ( get_query_var('operators_actv', null) ) {
        // use "get_stylesheet_directory()" or "get_template_directory()"
        // if template file is in theme directory 
        $template =  dirname(__FILE__) . '/se332319_custom_template.php';
    }
    return $template;
}

Don't forget to refresh permalinks. Click Save in Dashboars -> Settings -> Permalinks or do it from code with flush_rewrite_rules() (how to recreate rewrite rules).

In the link you attached, you have everything you need. You should:

  • add query variable (e.g operators_actv),
  • add rewrite rule that sets this variable (operators_actv),
  • use the template_include action hook to load custom template if query variable operators_actv is set.

Code:

add_filter( 'query_vars', 'se332319_custom_query_vars' );
add_filter( 'template_include', 'se332319_custom_template', 50 );
add_action( 'generate_rewrite_rules', 'se332319_resources_cpt_generating_rule' );

function se332319_resources_cpt_generating_rule( $wp_rewrite ) 
{
    $rules = [
        'operators/([^/]+)/?$' => 'index.php?operators_actv=$matches[1]'
    ];
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;

    return $wp_rewrite;
}

function se332319_custom_query_vars( $query_vars )
{
    array_push( $query_vars, 'operators_actv' );
    return $query_vars;
}

function se332319_custom_template( $template )
{
    $qv = get_query_var('operators_actv', null);
    if ( $qv !== null && term_exists($qv, 'activites') !== null ) { 

        // use "get_stylesheet_directory()" or "get_template_directory()"
        // if template file is in theme directory 
        $template =  dirname(__FILE__) . '/se332319_custom_template.php';
    }
    return $template;
}

Don't forget to refresh permalinks. Click Save in Dashboars -> Settings -> Permalinks or do it from code with flush_rewrite_rules() (how to recreate rewrite rules).

Source Link
nmr
  • 4.5k
  • 2
  • 17
  • 25

In the link you attached, you have everything you need. You should:

  • add query variable (e.g operators_actv),
  • add rewrite rule that sets this variable (operators_actv),
  • use the template_include action hook to load custom template if query variable operators_actv is set.

Code:

add_filter( 'query_vars', 'se332319_custom_query_vars' );
add_filter( 'template_include', 'se332319_custom_template', 50 );
add_action( 'generate_rewrite_rules', 'se332319_resources_cpt_generating_rule' );

function se332319_resources_cpt_generating_rule( $wp_rewrite ) 
{
    $rules = array();
    $terms = get_terms( array(
        'taxonomy' => 'activites',
        'hide_empty' => false,
    ) );

    $post_type = 'operator';
    foreach ($terms as $term) {
        $rules['operators/' . $term->slug . '/?$'] = 'index.php?operators_actv='.$term->slug;            
    }
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;

    return $wp_rewrite;
}

function se332319_custom_query_vars( $query_vars )
{
    array_push( $query_vars, 'operators_actv' );
    return $query_vars;
}

function se332319_custom_template( $template )
{
    if ( get_query_var('operators_actv', null) ) {
        // use "get_stylesheet_directory()" or "get_template_directory()"
        // if template file is in theme directory 
        $template =  dirname(__FILE__) . '/se332319_custom_template.php';
    }
    return $template;
}

Don't forget to refresh permalinks. Click Save in Dashboars -> Settings -> Permalinks or do it from code with flush_rewrite_rules() (how to recreate rewrite rules).