Grabbing data from Wordpress database

Discussion in 'PHP' started by goneinsane, Feb 1, 2012.

  1. #1
    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.

    Here's what I have:
    $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):
    Any help at all would be truly appreciated. Thank you.
     
    goneinsane, Feb 1, 2012 IP