• Hello,

    Our site publishes weekly issues. Each issue has a number and all our articles have a custom field where we indicate the number of the issue.

    On every page of the site, in a side bar, a custom field query displays the summary : a list of all the articles of a given issue, and just below the title, the author of the article.

    Here is the code I use :

    <?php global $wpdb; global $post;
    
    $sommaire = "
    SELECT wposts.*
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
       WHERE wposts.ID = wpostmeta.post_id
       AND wpostmeta.meta_key = 'numero'
       AND wpostmeta.meta_value = '192'
       AND wposts.post_status = 'publish'
       AND wposts.post_type = 'post'
       ORDER BY wposts.post_date DESC
     ";
    // List the posts
    	$thelist = $wpdb->get_results($sommaire, OBJECT);
    foreach ($thelist as $post): ?>
    
    <a href="<?php the_permalink(); ?>"><?php the_title();?></a>
    
    <?php $author = get_the_author();echo $author; ?>
    
    <?php endforeach; ?>

    The query works fine but I have a big problem with the authors : on single pages, my code is only able to retrieve the author of the article of the very page I’m on, NOT the various authors of the summary.

    As a result, in my sidebar, all the listed articles have the same wrong author !

    What am I doing wrong ? The SQL query retrieves the title all right, the permalink all right. Why not the auhor ?

    Note : I have tried with php the_author() instead of get_the_author(). The result is the same

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Custom field query, SQL, and wrong author’ is closed to new replies.