generate functionThu, 22 Dec 2022

get all wordpress published posts into array of id, link and title

function getallposts() { $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1 ); $posts = get_posts($args); $return = []; foreach ($posts as $post) { $return[] = array( "id" => $post->ID, "link" => get_permalink($post->ID), "title" => get_the_title($post->ID) ); } return $return; } $allposts = getallposts();

Questions about programming?Chat with your personal AI assistant