I have an average PHP website that calls on a database from another website running Wordpress. Right now, my website is displaying ads from 4 different categories, on one page. I would like it to continue to display ads from these categories but they must all be from the same city. The city information is stored in the wp_postmeta table of the database. The meta_key is cp_city and the meta_value must be New York. I am wondering what I can do here to make it happen. I think that there's a fairly simple solution. The person who provides an answer that works will get $5.50 in paypal once I have tested it. If you want to solve but feel that $5.50 isn't enough, please explain what you would charge to help me. Here is the current code: $querystr = " SELECT posts.ID AS ID, posts.post_title AS title, posts.post_content AS content FROM wp_posts posts INNER JOIN wp_term_relationships relationships ON posts.ID = relationships.object_id INNER JOIN wp_term_taxonomy taxonomy ON relationships.term_taxonomy_id = taxonomy.term_taxonomy_id INNER JOIN wp_terms terms ON taxonomy.term_id = terms.term_id WHERE posts.post_status = 'publish' AND terms.slug = '".CATEGORY."' OR posts.post_status = 'publish' AND terms.slug = '".CATEGORY2."' OR posts.post_status = 'publish' AND terms.slug = '".CATEGORY3."' OR posts.post_status = 'publish' AND terms.slug = '".CATEGORY4."' ORDER BY posts.post_date DESC LIMIT " . $querystart . ", " . ITEMS_PER_PAGE; $result = mysql_query($querystr); Code (markup):
$querystr = " SELECT posts.ID AS ID, posts.post_title AS title, posts.post_content AS content FROM wp_posts posts INNER JOIN wp_term_relationships relationships ON posts.ID = relationships.object_id INNER JOIN wp_term_taxonomy taxonomy ON relationships.term_taxonomy_id = taxonomy.term_taxonomy_id INNER JOIN wp_terms terms ON taxonomy.term_id = terms.term_id INNER JOIN wp_postmeta postmeta ON posts.ID = postmeta.post_id WHERE posts.post_status = 'publish' AND terms.slug = '".CATEGORY."' OR posts.post_status = 'publish' AND terms.slug = '".CATEGORY2."' OR posts.post_status = 'publish' AND terms.slug = '".CATEGORY3."' OR posts.post_status = 'publish' AND terms.slug = '".CATEGORY4."' AND meta_key = 'cp_city' AND meta_value = 'New York' ORDER BY posts.post_date DESC LIMIT " . $querystart . ", " . ITEMS_PER_PAGE; $result = mysql_query($querystr); PHP:
Didn't work. It just kept repeating the most recent ad 75 times. I removed the 2 "AND" lines that are near the bottom to run a test and the exact same thing happened, the same ad repeated 75 times. The one ad that kept repeating in both tests wasn't in New York, it was just the most recent ad so I think it's safe to say that the problem was with the JOIN.