WordPress.org

Ready to get started?Download WordPress

Forums

Custom Fields Query - include category and author in query (7 posts)

  1. globalkris
    Member
    Posted 5 years ago #

    Hi. I have a form on my site that asks users to choose the value for each of 4 custom fields. I then have a query that results in all of the posts that match the values they gave. I want to add to the form so the user can also choose category and author so that the query only fetches posts that match all the custom field values and the category and the author chosen.

    So far, I have this, which works for the custom fields query:

    $querystr = "
        SELECT wposts.*
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta, $wpdb->postmeta wpostmeta2,
    	$wpdb->postmeta wpostmeta3, $wpdb->postmeta wpostmeta4
        WHERE wposts.ID = wpostmeta.post_id
    	AND wposts.ID = wpostmeta2.post_id
    	AND wposts.ID = wpostmeta3.post_id
    	AND wposts.ID = wpostmeta4.post_id
    	AND wpostmeta.meta_key = 'gametype'
    	AND wpostmeta.meta_value LIKE '$gametype'
    	AND wpostmeta2.meta_key = 'gameformat'
            AND wpostmeta2.meta_value LIKE '$gameformat'
    	AND wpostmeta3.meta_key = 'gamelimit'
    	AND wpostmeta3.meta_value LIKE '$gamelimit'
    	AND wpostmeta4.meta_key = 'numberoftables'
    	AND wpostmeta4.meta_value LIKE '$numberoftables'
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        ORDER BY wposts.post_date DESC
     ";

    I've been reading a lot of posts on here (in particular, I tried the code from: http://wordpress.org/support/topic/121011?replies=15 and the code from: http://wordpress.org/support/topic/161154?replies=10" but I keep getting 'Parse error: syntax error, unexpected T_VARIABLE in' even when I copy the code exactly and change only the meta_key name.

  2. globalkris
    Member
    Posted 5 years ago #

    Bump, cause I'm really stuck :-/

  3. globalkris
    Member
    Posted 5 years ago #

    anyone? please :)

  4. globalkris
    Member
    Posted 5 years ago #

    Ok - how about this: why doesn't the following code work, which I copied exactly from:
    http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

    I get a 'Parse error: syntax error, unexpected T_VARIABLE''

    SELECT * FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE $wpdb->term_taxonomy.term_id = 1,2,3
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->postmeta.meta_key = 'paragraf'
    ORDER BY $wpdb->postmeta.meta_value ASC
  5. globalkris
    Member
    Posted 5 years ago #

    Bit hard to get a response around here...

    Bump

  6. Franz Josef Kaiser
    Member
    Posted 5 years ago #

    hi globalkris,

    could you post your query too?

  7. seborgarsen
    Member
    Posted 4 years ago #

    Any luck?

Topic Closed

This topic has been closed to new replies.

About this Topic