Created
July 13, 2021 19:31
-
-
Save jorpdesigns/4303a0602120b0d809cea2f70f717d7c to your computer and use it in GitHub Desktop.
Function for querying posts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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