• The idea is to redirect to another page that will have the detail shortcode in it with sidebar which is not wanted in the list page.
    I get ‘The page isnt redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete.’

    As far as I have read wp_redirect is the correct way in wordpress and I have no idea why it isnt working.

    
    [php]
    function get_list(){
    global $post; // required
    if (isset($_POST['get_detail'])){
    	$ID = $_POST['get_detail'];
    	call_user_func('get_itemdetail', '$ID');
    } else {
    $args = array('post_type' => 'cat'); 
    $custom_posts = get_posts($args);
    foreach($custom_posts as $post) : setup_postdata($post);
    	$this_post = $post->ID; ?>
            <form action="." method="post" name="get_detail"><input type="hidden" id="" name="get_detail" value="<?php echo($this_post); ?>"><input value="View Detail" type="submit"></form>
    <?php
    endforeach;
    } // end if is set
    }
    add_shortcode ('list', 'get_list');
    
    function get_itemdetail(){
    wp_redirect( '/detail-page/' );
    exit;
    global $post; // required
    $args = array('p' => $ID, 'post_type' => 'cat');
    $loop = new WP_Query($args);
    while ( $loop->have_posts() ) : $loop->the_post();
        ...... 
    endwhile;	
    }
    add_shortcode ('detail', 'get_itemdetail')
    
    [/php]
    
    • This topic was modified 4 years, 8 months ago by Jan Dembowski. Reason: Formatting and moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 1 replies (of 1 total)
  • Hi

    Please remove wp_redirect( '/detail-page/' ); exit; from the ‘get_itemdetail’ function and in place of call_user_func('get_itemdetail', '$ID'); write wp_safe_redirect( esc_url( add_query_arg( 'id', $ID, 'YOUR_SITE_URL/detail-page/' ) ) ); exit;. Now, it will redirect to the detail-page with a query var like this – /detail-page/?id=YOUR_ID_HERE

    In the ‘get_itemdetail’ function you can fetch the id using the following code:

    if (isset($_GET['id'])){
          $ID = $_GET['id];
    }

    I hope this will help you.

    Kind regards

Viewing 1 replies (of 1 total)
  • The topic ‘redirecting to a page within wordpress functions’ is closed to new replies.