2014-11-08 39 views
0

我正在wordpress中創建一個自定義搜索查詢和帖子標題不匹配。我希望它能說明郵件和全名必須是完全匹配的,否則就不會有任何結果出現。我的Post_titles全部是5位數字。但截至目前,我可以輸入正確的全名,但使用與帖子標題不匹配的任何數字,並且它仍然顯示。兩者都需要完全匹配。有什麼建議在這裏做什麼?我如何使查詢使用確切的職位標題

<?php 
      /* Search Results */ 
$patientid = '48392'; //Example only but must match exactly AND fullname should match exact too 
$fullname = 'John Doe'; //Example only. Exact match IS working on this but not AND 

$args = array('posts_per_page' => 2, 'post_type' => 'patients', 'post_title' => $patientid, 
'meta_query' => array(
    array(
    'key'  => 'fullname', 
    'value' => $fullname, 
    'compare' => '=', 
    ), 
),); 

    query_posts($args); 
?> 

回答

1

您可以這樣做query_posts沒有帖子標題作爲參數。

$patient = get_page_by_title($patientid, 'OBJECT', 'patients'); // get the post object by title and cpt 

if($patient) { 
    $patient_fullname = get_post_meta($patient->ID, 'fullname', true); // get the post meta 
    if($patient_fullname == $fullname) { 
     // here both conditions are true. 
    } 
} 
+0

謝謝!我嘗試一下,讓你知道。 – user2593041 2014-11-09 01:07:06

+0

它的工作,但由於某種原因,如果一個人是一個標題00202,我可以鍵入00201,並仍然顯示。但它只能在00100到00202之間,任何其他數字都會出現錯誤。但它確定,我不認爲在100位數字內會有任何同名的人。謝謝! – user2593041 2014-11-10 02:26:32

+0

它可以返回你的草稿和垃圾,所以確保它的劑量情況..並過濾這個'$ patient-> post_status'確保狀態是發佈。 – Shibi 2014-11-10 03:18:29