• honzik

    (@honzik)


    Hello.
    I want to display a Custom Fields from data base outside the loop, for exemple in this plugin (Igit related posts wordpress plugin). I want to disply the custom field after the image generated by this plugin. Can You help me ?

    With this code <?php echo get_post_meta($GLOBALS['current_id'], "custom-field-name", true); ?> in footer.php or sidebar.php everything seems ok, but the custom field not appear if i put this code on the plugin files.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Just learned this… You can display custom fields outside of the loop with the following code.

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'Your-Custom-Field', true);
    wp_reset_query();
    ?>

    Reference:
    https://www.wpbeginner.com/wp-themes/how-to-display-custom-fields-outside-the-loop-in-wordpress/

    Hope that helps and good-luck!

    Thread Starter honzik

    (@honzik)

    Not work. I habe a blank page with this code. Is not ok !

    A blank page is a PHP error. Dig into your server’s error logs to find out why the code didn’t work.

    Thread Starter honzik

    (@honzik)

    [Tue Apr 05 16:39:15 2011] [error] [client xxx.xxx.xx.xx] PHP Parse error: syntax error, unexpected T_STRING in /var/www/vhosts/site.com/httpdocs/wp-content/plugins/igit-related-posts-with-thumb-images-after-posts/inc/core.php on line 393, referer: https://www.site.com/

    Turn of the igit-related-posts-with-thumb-images-after-posts plugin and things should work again. Also, you may need to go in via FTP and delete the plugin (back it up first if needed).

    Thread Starter honzik

    (@honzik)

    Hey, I want to put this code to show the price (custom field) after every image generated by this pugin.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Fields from data base outside the loop’ is closed to new replies.