“Pencarian WordPress di bidang khusus” Kode Jawaban

Cari WordPress dengan bidang khusus

function me_search_query( $query ) {
  if ( $query->is_search ) {
    $meta_query_args = array(
      array(
        'key' => 'your_key',
        'value' => $query->query_vars['s'],
        'compare' => 'LIKE',
      ),
    );
    $query->set('meta_query', $meta_query_args);
    add_filter( 'get_meta_sql', 'me_replace_and_with_or' );
  };
}

function me_replace_and_with_or( $sql ) {
    if ( 1 === strpos( $sql['where'], 'AND' ) ) {
        $sql['where'] = substr( $sql['where'], 4 );
        $sql['where'] = ' OR ' . $sql['where'];
    }

    //make sure that this filter will fire only once for the meta query
    remove_filter( 'get_meta_sql', 'me_replace_and_with_or' );
    return $sql;
}

add_filter( 'pre_get_posts', 'me_search_query');
Blue-eyed Baboon

Pencarian WordPress di bidang khusus

If someone is looking for a solution to this problem is to recommend the plugin:
https://wordpress.org/plugins/acf-better-search/
miner

Pencarian WordPress di bidang khusus

So, I did another search today and this was worked first time. http://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/
miner

Jawaban yang mirip dengan “Pencarian WordPress di bidang khusus”

Pertanyaan yang mirip dengan “Pencarian WordPress di bidang khusus”

Lebih banyak jawaban terkait untuk “Pencarian WordPress di bidang khusus” di HTML

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya