Support » Fixing WordPress » How I FILTER a DB search by category name?? (Experts)

  • Resolved pepereina


    Hi people,

    I developed a hack in order to show some posts in a page of my blog with some of my criteria (such as show future posts, etc.). The fact is that I was only filtering depending on the category in which the post was and what was my surprise that I fail to see how to identify such property in the database. He used $ wpdb-> get_results to connect to the table ‘wp_posts’ and take away all the information I need, but can not find in this table how to get the name ID or category of post and thus able to filter what I want to do.

    My question is: how can I filter using the database, a result of posts using the name / ID of the category this post?

    Thanks in advance. I thought that the code would post a column of the table wp_post but this has not happened and has been a great disappointment because I think now complicates everything 🙁

Viewing 3 replies - 1 through 3 (of 3 total)
  • moshu


    This might help: WordPress_Taxonomy



    Thanks moshu but i have no idea about how i can implement Taxonomy on my database petition 🙁

    My database petition is this one:

    $results = $wpdb->get_results("SELECT ID, post_title, post_date_gmt, post_date FROM $wpdb->posts WHERE post_status = 'publish' AND post_date >= '$today' ORDER BY post_date ASC LIMIT 10", ARRAY_N)

    I only have to add on filter one AND more on WHERE, the filter that restrict the query to a one category name

    Thank you again



    Ok, i resolved at final.

    I added this on get_restuls database consult

    INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
      									WHERE wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id IN ('$categoria')

    where $categoria is the category ID

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How I FILTER a DB search by category name?? (Experts)’ is closed to new replies.