function add_listing( $atts)
 { extract( shortcode_atts( array (
'sslug' => '',
'jslug' => ''
  ), $atts ) );

global $wpdb;
$qstr = '   
FROM $wpdb->posts   
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)    
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
WHERE $wpdb->posts.post_type = "states" 
AND $wpdb->posts.post_status = "publish"
AND $wpdb->term_taxonomy.taxonomy = "usstates"
AND $wpdb->term_taxonomy.taxonomy = "job-desc" 
AND $wpdb->terms.slug =  $sslug;   <-----
OR $wpdb->terms.slug =   $jslug;    <--------
ORDER BY $wpdb->posts.post_date DESC
  add_shortcode("list", "add_listing");

i want to subtitute the value like for example:

here's my sample shortcode

[list sslug="alabama" jslug="electrician"]

i want to subtitute the value to the arrow above

but cant get it to work :(

please help guys


If you put variables inside a string, you have to use " double quotes.


// This:
$qstr = '
ORDER BY $wpdb->posts.post_date DESC

// becomes...
$qstr = "
ORDER BY $wpdb->posts.post_date DESC
  • 1
    He should be using the prepare method for those two items, but you're correct about the double quotes as well. He also has a taxonomy problem since he's got $wpdb->term_taxonomy.taxonomy = "usstates" AND $wpdb->term_taxonomy.taxonomy = "job-desc", which will always be false. – Otto Aug 30 '11 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.