• Hello,

    I’m trying to compose a quite complex MySQL query and don’t seem to get my head around it (I’m not a MySQL pro).
    The query should return the published post(s) that have one or more approved comment which match a search term (this part works fine!) and aren’t listed in one or more particular categories (that’s where I’m stuck).

    Here’s my code:

    SELECT DISTINCT c.comment_ID AS unionCommentID, p.ID AS unionID, p.post_date AS unionDate, p.post_title AS unionTitle, c.comment_content AS unionDescription, c.comment_author AS unionAuthor, p.post_name AS unionSlug, p.post_name AS unionPermalink, 'comment' AS unionType,
    MATCH (
    c.comment_content
    )
    AGAINST (
    'search_term'
    ) AS relevancy
    FROM wp_comments AS c, wp_posts AS p, wp_terms AS t, wp_term_taxonomy AS tt, wp_term_relationships AS tr
    WHERE p.ID = c.comment_post_ID
    AND p.ID = tr.object_id
    AND tr.term_taxonomy_id = tt.term_taxonomy_id
    AND t.term_id = tt.term_id
    AND
    t.term_id NOT
    IN (
    '1', '2', '3', '25'
    )
    AND p.post_status = 'publish'
    AND c.comment_approved = '1'
    AND MATCH (
    c.comment_content
    )
    AGAINST (
    'search_term'
    )

    ANY help or hint would be highly appreciated.
    Thanks a lot,
    —trice

  • The topic ‘Advanced MySQL query’ is closed to new replies.