From a8b3166698541a099f9a2729d3b65c3a5be5f1f0 Mon Sep 17 00:00:00 2001
From: Harish Tewari <42291682+tewariharish@users.noreply.github.com>
Date: Sat, 16 Dec 2023 13:54:30 +0530
Subject: [PATCH] Search by post ID
Add feature to search by post ID.
---
zoninator.php | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/zoninator.php b/zoninator.php
index bfb74d8..d1ac925 100644
--- a/zoninator.php
+++ b/zoninator.php
@@ -690,7 +690,7 @@ function zone_admin_recent_posts_dropdown( $zone_id ) {
function zone_admin_search_form() {
?>
@@ -835,6 +835,17 @@ function ajax_search_posts() {
$limit = $this->posts_per_page;
$exclude = (array) $this->_get_request_var( 'exclude', array(), 'absint' );
+ if ( is_numeric( $q ) ) {
+ $story_id = intval( $q );
+ $title = ! empty( $story_id ) && ! empty( get_the_title( $story_id ) ) ? get_the_title( $story_id ) : '';
+ $stripped_posts[] = array(
+ 'post_id' => $story_id,
+ 'title' => ! empty( $title ) ? $title : __( '(no title)', 'zoninator' ),
+ 'date' => get_the_time( get_option( 'date_format' ), $story_id ),
+ 'post_type' => 'post',
+ 'post_status' => 'publish',
+ );
+ } else {
$args = apply_filters( 'zoninator_search_args', array(
's' => $q,
'post__not_in' => $exclude,
@@ -866,14 +877,14 @@ function ajax_search_posts() {
foreach( $query->posts as $post ) {
$stripped_posts[] = apply_filters( 'zoninator_search_results_post', array(
- 'title' => ! empty( $post->post_title ) ? $post->post_title : __( '(no title)', 'zoninator' ),
+ 'title' => ! empty( $post->ID ) ? get_the_title( $post->ID ) : __( '(no title)', 'zoninator' ),
'post_id' => $post->ID,
'date' => get_the_time( get_option( 'date_format' ), $post ),
'post_type' => $post->post_type,
'post_status' => $post->post_status,
), $post );
}
-
+ }
echo json_encode( $stripped_posts );
exit;
}