Forums

[resolved] How to use an array variable as the WHERE clause in a WPDB call (2 posts)

  1. sb_cole
    Member
    Posted 5 months ago #

    Hey guys,

    So I have this code set up:

    $rows = $wpdb->get_results("
    	SELECT ID, post_title
    	FROM $wpdb->posts
    	WHERE post_type = 'page'
    	AND ID IN('206','176','200','196','68','129')"
    );

    Which works as expected. However, I need to replace the last line and all the hard-coded numbers with an array var that I have created already so it would read something like:

    AND ID IN($page_numbers)

    This however fails. Any ideas how to include an array such as I'm doing here?

  2. sb_cole
    Member
    Posted 5 months ago #

    I found the solution to my problem. I had removed the commas from my list of values while gathering those numbers into an array. Duh. Anyway, if anyone ends up here looking for something along these lines, make sure you are passing a commma-delimited array of values.

Reply

You must log in to post.

About this Topic