WordPress.org

Ready to get started?Download WordPress

Forums

Query that finds a custom field in wp_postmeta from a given post ID (1 post)

  1. Nikolas
    Member
    Posted 4 years ago #

    Finally I am into this query. The following, finds 5 post IDs from authors that they have a last_name in their meta_key.
    In my blog, I use a custom field name thumbnail (inside wp_postmeta).
    However, I am having some difficulty to make the ID of a post to search into wp_postmeta, find it's thumbnail and show it.
    Any help is appreciate. This drives me crazy the last days...

    <?php
    
     $querystr = "
        SELECT wposts.ID
        FROM $wpdb->posts wposts, $wpdb->usermeta usermeta
        WHERE wposts.post_author = usermeta.user_id
        AND usermeta.meta_key = 'last_name'
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        AND wposts.post_date < NOW()
        ORDER BY wposts.post_date desc limit 5
     ";
    
     $postids = $wpdb->get_col($querystr);
    
    foreach ($postids as $postid) {
         echo "<p>$postid</p>";
     }
    
    ?>

    Maybe the following will give a help to someone...

    <?php
    $thumb = get_post_meta($post->ID, "thumb", true);
    <img src="<?php $values = get_post_custom_values("thumb")>
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.