<?php
function file_search_shortcode() {
ob_start();
?>
<form method=”get”>
<input type=”text” name=”search_file” placeholder=”ফাইলের নাম লিখুন” />
<input type=”submit” value=”সার্চ করুন” />
</form>
<?php
if (isset($_GET[‘search_file’]) && !empty($_GET[‘search_file’])) {
$search = sanitize_text_field($_GET[‘search_file’]);
$args = array(
‘post_type’ => ‘attachment’,
‘post_status’ => ‘inherit’,
‘posts_per_page’ => -1,
‘s’ => $search,
);
$attachments = get_posts($args);
if ($attachments) {
echo ‘<ul>’;
foreach ($attachments as $attachment) {
$file_url = wp_get_attachment_url($attachment->ID);
$file_name = get_the_title($attachment->ID);
echo ‘<li><a href=”‘ . esc_url($file_url) . ‘” target=”_blank”>’ . esc_html($file_name) . ‘</a></li>’;
}
echo ‘</ul>’;
} else {
echo ‘কোনো ফাইল পাওয়া যায়নি।’;
}
}
return ob_get_clean();
}
add_shortcode(‘file_search’, ‘file_search_shortcode’);

