searching in custom meta field

After thinking about the problem, I found the simplest solution, do a direct query using $wpdb

in archive-{post-type}.php

<?php 

global $wpdb;
$meta_key = get_query_var('publisher');
$result = $wpdb->get_results("
    SELECT  * 
    FROM  " . $wpdb->prefix. "postmeta_books 
    WHERE publisher LIKE  '%$meta_key%' 
");
foreach( $result as $results ) {

        echo $results->publisher;
        echo '<br/>';
        

    }
?>

It is the basic query, it needs to be refined but I wanted to share it to close the question. of course work very well.

Leave a Comment