This topic has 5 replies, 3 voices, and was last updated 9 years by Radu.

  • Author
  • #81112
     HDcms
    Participant

    Hello,


    I am looking to do a redirect on the groups page to redirect to the membership level if the member is already in 5 groups

    This does not work and after a few hours I realized that is_page condition does not work in the child theme functions.php

    Do you have an idea ?

    if (is_page(10) AND (bp_get_total_group_count_for_user($user_id) >5) ) { //
    echo ‘<h2>PAGE 10</h2>’;
    wp_redirect(pmpro_url(“levels”));
    exit;
    }

     

    Regards

    #81406
     Laura
    Moderator

    Hello, will assign the ticket to a higher support lever who can help and advise you in your query.
    Thanks! 🙂

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    Laura Solanes - Graphic Designer and Web Designer

    Please be patient as I try to answer each topic as fast as i can.

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Always happy to help you 🙂

    #82156
     HDcms
    Participant

    Hi,
    It does not work :

    COPY CODE
    
    global $post;
    $p = $post->ID;
    echo '<br>$p: ' .$p;
    
    $Getid = get_the_ID();
    echo '<br>Getid: ' .$Getid;

    It work:

    COPY CODE
    $url = explode('?', 'http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
    $ID = url_to_postid($url[0]);
    echo '$ID: ' .$ID;

    but not:

    COPY CODE
    if ( is_page($ID) ) { 
    echo '$ID: ' .$ID;
    echo '<h2>PAGE 10</h2>';
    //wp_redirect(pmpro_url("levels"));
    //exit;
    }
    

    ??

    #82365
     Radu
    Moderator

    Hi,

    Please be sure you are adding the redirect logic in the right action hook, see here an good example

    https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect#Examples

    Regards

    Radu

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #82722
     HDcms
    Participant

    HI,
    Thanks for your answer.
    I have done several test. It does not work
    Apparently is_page does not work in the child theme function.php !?

    COPY CODE
    function my_page_template_redirect()
    {
        if (is_page(10)) // is_page('groupes') 
        {
         //   wp_redirect( home_url( '/inscription/' ) );
         // wp_redirect('http://127.0.0.1/wordpress/wp_test/inscription/' );
          echo '<h2>PAGE 10</h2>';
          //  exit();
        }
    }
    add_action( 'template_redirect', 'my_page_template_redirect' );
    #83153
     Radu
    Moderator

    Hi,

    It works for me

    COPY CODE
    
    function my_page_template_redirect()
    {
        if (is_page('groups')) 
        {
        wp_redirect( home_url( '/testtheredirect/' ) );
        }
    }
    add_action( 'template_redirect', 'my_page_template_redirect' );
    

    Make sure the child theme is installed and activated

    Regards

    Radu

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Log in with your credentials

Forgot your details?