sql >> Base de Datos >  >> RDS >> Mysql

¿Cómo puedo recuperar publicaciones con imágenes destacadas de una base de datos de WordPress si WordPress ya no está instalado?

Su mejor apuesta sería MySQLI .

<?php

$wp_database = new mysqli("yourhost", "yourusername", "yourpasssword", "yourdatabase");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

// Here's how you get all the posts. Adjust table names to suit.

$sql = "SELECT * FROM `wp_posts` WHERE `post_status` LIKE 'publish' AND `post_type` LIKE 'post'";

$result =  mysqli_query($wp_database, $sql);

$posts = mysqli_fetch_all($result, MYSQLI_ASSOC);
mysqli_free_result($result);
foreach ($posts as $post): ?>
<div>
    <?php print_r($post); ?>
</div>

<?php endforeach;

// And here's how you get an individual image url.

$post_id = 1181; // Your post ID here

$sql = "SELECT `guid` FROM `wp_posts` WHERE `id` IN (SELECT  `meta_value` 
FROM  `wp_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; ?>