Buying PHP help grabbing data from Wordpress database

Discussion in 'Programming' started by goneinsane, Feb 2, 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.

    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):

     
    goneinsane, Feb 2, 2012 IP
  2. creativeGenius

    creativeGenius Well-Known Member

    Messages:
    273
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    120
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    
    $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:
     
    creativeGenius, Feb 2, 2012 IP
  3. goneinsane

    goneinsane Well-Known Member

    Messages:
    303
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    As Seller:
    100% - 1
    As Buyer:
    100% - 0
    #3
    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.
     
    goneinsane, Feb 2, 2012 IP
  4. goneinsane

    goneinsane Well-Known Member

    Messages:
    303
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    As Seller:
    100% - 1
    As Buyer:
    100% - 0
    #4
    creativeGenius is working on it. No more PM's please.
     
    goneinsane, Feb 3, 2012 IP
  5. zappak

    zappak Active Member

    Messages:
    366
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    80
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    may be it can help you

     
    zappak, Feb 3, 2012 IP