1

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]

1
  • Oh man your my hero! finally! Commented Oct 18, 2017 at 13:33

2 Answers 2

4

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; ?>
Sign up to request clarification or add additional context in comments.

Comments

0

Can you try this:

<?php print_r($image['guid']); ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.