WordPress.org

Ready to get started?Download WordPress

Forums

POP UP A Custom Field Value From Parent Page (2 posts)

  1. Nic Windley
    Member
    Posted 1 year ago #

    Hello All,

    I'm trying to pop up some content which is contained in a custom field stored in a parent page to a child page (not post).

    I've got the pop up working which is bascially displaying the results of a PHP file in an iframe.

    The PHP file contains the following script which is failing to get the content I'm after.

    <?php
    require_once('/home/XXXXXX/public_html/wp-blog-header.php');
    require_once('/home/XXXXXX/public_html/wp-config.php');
    global $wp_query;
    if( empty($wp_query->post->post_parent) ) {
    $parent = $wp_query->post->ID;
    } else {
    $parent = $wp_query->post->post_parent;
    }
    $enquiryform = get_post_meta($parent, 'CUSTOMFIELD', true);
    if(empty($enquiryform)){
    } else {
    echo '<div id="product-enquiryform">';
    echo $enquiryform;
    echo '</div>';}
    ?>

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    As the PHP file is being pulled in from a sub folder on the WP installation I'm not sure I need the first two lines.

    The $parent is always empty so the data I'm after is not being requested correctly or shown.

    Can anybody advise why this isn't working and what I need to do to sort it.

    Thanks,

    Nic

  2. Nic Windley
    Member
    Posted 1 year ago #

    Ah! OK, just realised that if I'm iframing in this PHP page/script it has no knowledge of the current page/post ID so if I setup a session and pass that variable over to the php script/page being iframed in on the local server it should then be able to pull in the content I need.

Topic Closed

This topic has been closed to new replies.

About this Topic