• Resolved ibraheemhsn

    (@ibraheemhsn)


    hello every body

    I need a query using $wpdb to do the following:

    return all published posts that belongs to category :’cat3′ AND have one or more of these tags [‘tag1′,’tag2′,’tag3’,,,,,,etc];

    </string>
    thank you all

Viewing 5 replies - 1 through 5 (of 5 total)
  • Does query_posts('category_name=cat3&tag__in' => array(<ID1>,<ID2>)'); not work?

    Thread Starter ibraheemhsn

    (@ibraheemhsn)

    thanks I will check it and replay again

    Thread Starter ibraheemhsn

    (@ibraheemhsn)

    sorry but this method casued for me unexpected errors ,because I want to use secondary loop ,, using of $wpdb is more safety …

    I read this qoute in in wp-codex https://codex.www.ads-software.com/Template_Tags/query_posts

    The query_posts function is intended to be used to modify the main page Loop only. It is not intended as a means to create secondary Loops on the page. If you want to create separate Loops outside of the main one, you should create separate WP_Query objects and use those instead. Use of query_posts on Loops other than the main one can result in your main Loop becoming incorrect and possibly displaying things that you were not expecting.

    also I don’t want to use WP_QUERY object insted ,, I want to

    return all published posts that belongs to category :’cat3′ AND have one or more of these tags [‘tag1′,’tag2′,’tag3’,,,,,,etc]; using $wpdb

    Ok, then use this method to create another loop. Then print_r() the object and you should see the query in the output. Copy that and use it for your own $wpdb query.

    … not sure why you don’t want to use the query object though.

    Thread Starter ibraheemhsn

    (@ibraheemhsn)

    thanks MR.APLJDI
    that’s perfect .. the problem had been solved..

    why should I don’t want to use wp_query and other builtin wp functions ?
    OK ,,
    because I want to use another wordpress database as an external database and use raw sql queries to retrive the informations from the external database

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘complex wpdb query’ is closed to new replies.