0

I want to get a specific custom field value to display outside the wordpress loop in a new php page. right now im using the code below, which is doing what i want but in a ugly way. i need to exclude all custom fields except the one i want to get. instead of excluding, i would be happy if someone could provide me with a better code. so i can get just the custom field value that i want

    require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php');
    $postid = $_GET["postid"];;

    $custom = get_post_custom($postid);

    foreach ($custom as $key => $value) {
    if (($key != '_edit_lock' && $key != 'cwp_bar_icon' && $key !=     '_edit_last' && $key != 'send_onesignal_notification'&& $key != 'wp_noextrenallinks_mask_links'&& $key != 'wpb_post_views_count'&& $key != 'mp3'&& $key != 'wpb_post_views_count'&& $key != '_encloseme'&& $key != 'wpb_post_views_count'&& $key != '_pingme'&& $key != 'wpb_post_views_count'&& $key != '_is_video'&& $key != '_thumbnail_id'

))
        echo '<meta http-equiv="refresh" content="0; URL=' . $value[0] . '">';
}
  • Is this page resides outside of WP install? What exactly you want this page for? – Abhik Nov 13 '15 at 8:32
0

ok got it myself didnt thought it would be that simple

require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php');
$postid = $_GET["postid"];

$custom = get_post_custom($postid);

 {

        echo '<meta http-equiv="refresh" content="0; URL= ' . get_post_meta($postid, 'custom-filed-key', true) . ' ">';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.