Reputation: 456
I've been trying to combine two database queries in to one. Now I've finally done this (yeah). But One problem keeps me from completing this task. And I bet its really simple but I can't seem to get it to work.
I've a database query set-up and it works.
$sql = "SELECT `guid` FROM `pf_posts` WHERE `id` IN (SELECT `meta_value`
FROM `pf_postmeta`
WHERE `meta_key` LIKE '_thumbnail_id'
AND `post_id` = $post_id)";
$result = mysqli_query($wp_database, $sql);
$images = mysqli_fetch_all($result, MYSQLI_ASSOC);
mysqli_free_result($result);
foreach ($images as $image): ?>
<div>
<?php print_r($image); ?>
</div>
<?php endforeach; ?>
This get's me the correct value BUT in a print_r
which get's me this:
Array ( [guid] => http://mydomein.nl/wp-content/images-001.jpg )
But I would like to remove the Array ( [guid] =>
and the last )
part from the print_r.
I've looked into string replace but I have no idea how to set correct. I would like to be able to echo
it. I've gotten the code for the database from here:
How can I retrieve posts with featured images from a WordPress database if WordPress is no longer installed? [closed]
Upvotes: 1
Views: 54
Reputation: 9947
print_r
will print a human-readable representation of the argument. In your case, $image
is an array
with one element, key "guid" and value "http://mydomein.nl/wp-content/images-001.jpg".
So, what you need to do is just echo
the element you want:
<?php
foreach ($images as $image): ?>
<div>
<?php echo $image["guid"] ?>
</div>
<?php endforeach; ?>
Upvotes: 4