Support » Themes and Templates » List custom posts for a certain author meta value

  • PLEASE HELP I’m new to PHP – this may be a simple issue but I have spent hours on it and I’m going mad.

    I am trying to retrieve a list of custom posts where the author has a certain meta value.

    I have no problems getting the custom posts.
    I have no problems getting the authors with the specific author meta value.

    How to combine to two???

    In my template file for the relevant page I have this code::

    $authors = $wpdb->get_results("SELECT user_id FROM $wpdb->usermeta WHERE meta_value='Waterfront City'");
    foreach ($authors as $author) {
    	echo = $author->user_id.",";
    $authorsids = "5,6,";
    $args = array( 'post_type' => 'deal', 'author' => $authorsids, 'paged' => get_query_var( 'paged' ), 'posts_per_page' => 6 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();'

    This does exactly what I want. Now for the BIG PROBLEM… $authorsids is not supposed to be defined manually at “5,6,” it is supposed to be defined authomatically using the results from the query on the Authors.

    Now the output of the foreach is identical to $authorsids however I cannot assign the output of the foreach to a variable as it breaks.

    What I’m trying to achieve in my mind is like this:

    $authorsids = foreach ($authors as $author) {
    	echo = $author->user_id.",";

    now this obviously is incorrect so please tell me how to do this.

    Also I need to add that I have to do it this way as I am using pagination.

    Without pagination I could achieve the desired output using an if statement relating to the specific author meta within the post loop.

    However this doesn’t work with pagination as the pagination is shown for all retrieved posts not just those displayed.

    Please help.

    Thanks in advance,


Viewing 2 replies - 1 through 2 (of 2 total)
  • Does anyone ever help out on these forums? I’m really struggling here and I don’t think what I’m asking is too difficult.

    Please please can someone let me know if they have done this. I’m sure someone out there must have done this before or at least be able to tell me what I am doing wrong with my limited knowledge of php.


    Hi, have you tried something like this:

    $authorsids = "";
    foreach($authors as $author) {
    	$authorsids .= $author->user_id.",";
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List custom posts for a certain author meta value’ is closed to new replies.