Question: I'm pretty new to PHP, I'm working in WordPress but I don't think that this question is WordPress specific. Basically, I've run a MySQL query that returns some numbers. In WordPress, you can use a function called wp\_list\_pages() to say exactly which pages you want to include in something, like this:

```
 wp_list_pages('include=161,164,167,171,172,173,174,185,188,135,141,&title_li=');

```

The three-digit numbers are all post ID's. What I wanted to do was to generate these numbers programmatically instead of hardcoding them. So, I use the following:

```
    $results = $wpdb->get_results("SELECT * FROM [table] WHERE [column] LIKE [string] ");
foreach($results as $returned_id) {$pagelist.=$returned_id->post_id.",";}

```

This works just fine (everything in brackets is replaced with actual information). It basically just creates a list in the $pagelist variable of numbers matching my SQL query. If I were to run "echo $results", the output would be "161,164,167..." etc., the exact list from the hardcoded version.

I would now like to replace the hardcoded version with the programmatic version - I was thinking it should be something like

```
wp_list_pages('include=$pagelist');

```

But this doesn't work. I want to replace $pagelist in that example with the contents of that variable. How would I do that?

Answer: 
**Option 1**

If you want variables to be evaluated, you need to use double quotes.

```
wp_list_pages("include=$pagelist")

```

or

```
wp_list_pages("include={$pagelist}")

```

**Option 2**

Use string concatenation

```
wp_list_pages('include=' . $pagelist);

```

**Option 3**

Use [`sprintf`](http://php.net/manual/en/function.sprintf.php)

```
wp_list_pages(sprintf('include=%s',$pagelist));

```
In PHP variables are only looked for in double quotes, other than that you are spot on. So use " instead of '

```
wp_list_pages("include=$pagelist");

```

Another thing you could do is concatenate the variable with the string with a . like this:

```
wp_list_pages('include='.$pagelist);

```