WordPress.org

Ready to get started?Download WordPress

Forums

how to retrieve custom field at root directory? (2 posts)

  1. radiofranky
    Member
    Posted 2 years ago #

    HI,
    i have create a redir.php and placed in the home directory to do the redirect. I want to pass in the post id and then retrieve a custom field value of the post and feed to header('location:'.$url);

    this is what I have, but it's not working. It gives me "Parse error: parse error in \redir.php on line 5"

    <?php
    
    require('./wp-blog-header.php');
        echo $id = $_GET['id'];
    	 echo $yes_price = get_field('deal_http_link',post->$id);
        /* header('Location:'.$id);*/
    ?>
  2. Chandan Kumar
    Member
    Posted 2 years ago #

    Create this redir.php page as redirection template, to do this make the following changes:

    <?php
    /**
     * The template for redirecting page.
     * Template Name: Redirection
     */
    
    global $post;
    //Get custom field value
    $redirect_url = get_post_meta($post->ID,'custom_field_name',true);
    wp_redirect($redirect_url);
    exit;
    ?>

    Now If you want to redirect any page then assign this template to that page with redirection url as custom field.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.