0

I got custom function where I retrieve guid's attached to each post. Now I want to add this on WordPress API.

global $wpdb;

$post_id= $object['id'];
$sql = "SELECT post_content FROM wp_posts WHERE id = $post_id";

$results = $wpdb->get_results($sql);

foreach ($results as $result) {
    $content = $result->post_content;

    $needle = 'gallery_ids="';

    $offset = strpos($content,$needle);

    if($offset>=0){
        $offset += strlen($needle);

        $l = strpos($content,'"',$offset);
        $l -= $offset;
        $content = substr($content,$offset,$l);
        $content = explode(",",$content);
        function filterGuid($var) {return is_numeric($var);}
        $content = array_filter($content,"filterGuid");

        for ($x = 0; $x <= count($content) -1; $x++) {
            $guids = "SELECT guid FROM wp_posts WHERE id IN ('$content[$x]')";
            $gui_results = $wpdb->get_results($guids);

            foreach ($gui_results as $result) {
                echo $result->guid;
            }
        }
    }
}

What changes to make to add it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.