Skip to content

Instantly share code, notes, and snippets.

@jorpdesigns
Created July 13, 2021 19:31
Show Gist options
  • Save jorpdesigns/4303a0602120b0d809cea2f70f717d7c to your computer and use it in GitHub Desktop.
Save jorpdesigns/4303a0602120b0d809cea2f70f717d7c to your computer and use it in GitHub Desktop.
Function for querying posts
<?php
function posts_query() {
// Parameters available here: https://developer.wordpress.org/reference/classes/wp_query/
$args = array(
'post_type' => 'post' // Replace with other post type if you want
);
$posts = get_posts( $args );
if ( $posts ) {
foreach ($posts as $post) {
$postID = $post->ID;
$postTitle = $post->post_title;
$postContent = wpautop( $post->post_content );
$postExcerpt = $post->post_excerpt;
$postLink = get_the_permalink( $postID );
}
wp_reset_postdata();
} else {
// No posts found
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment