WordPress.org

Ready to get started?Download WordPress

Forums

Custom Fields from data base outside the loop (7 posts)

  1. honzik
    Member
    Posted 3 years ago #

    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.

  2. rickmesser
    Member
    Posted 3 years ago #

    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:
    http://www.wpbeginner.com/wp-themes/how-to-display-custom-fields-outside-the-loop-in-wordpress/

    Hope that helps and good-luck!

  3. honzik
    Member
    Posted 3 years ago #

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

  4. Tim Moore
    Moderator
    Posted 3 years ago #

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

  5. honzik
    Member
    Posted 3 years ago #

    [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: http://www.site.com/

  6. Tim Moore
    Moderator
    Posted 3 years ago #

    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).

  7. honzik
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.