WordPress.org

Ready to get started?Download WordPress

Forums

List custom posts for a certain author meta value (3 posts)

  1. nicole2292
    Member
    Posted 2 years ago #

    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,

    Nicole

  2. nicole2292
    Member
    Posted 2 years ago #

    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.

    Thankyou,
    Nicole

  3. Webartisan
    Member
    Posted 2 years ago #

    Hi, have you tried something like this:

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

Topic Closed

This topic has been closed to new replies.

About this Topic