Currently I have this wordpress code to show a list of the last modified or updated posts, the problem is that I have a contact form plugin, when someone sends a message through the form it is automatically shown in the list of the last modified posts .
Any way to only allow showing posts, pages and custom post type and exclude that?
This is my code:
<?php
$today = current_time('mysql', 1);
$count = 8;
if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $count")):
?>
CodePudding user response:
just add a post_type
filter on your query,
should be something like
SELECT ID, post_title
FROM $wpdb->posts
WHERE post_status = 'publish'
AND post_modified_gmt < '$today'
AND post_type = 'post' // or if you want to query both post and page just do -> AND post_type IN ('post', 'page')
ORDER BY post_modified_gmt
DESC
LIMIT $count