2014-07-25 22 views
-1

wp_posts自定義查詢我創建了從WordPress的wp_posts自定義查詢,我需要知道,如果它的正確的,因爲我收到了此行的錯誤:在WordPress的

<li><a href="the_permalink()"> the_title() </a></li> 

錯誤聽起來像這樣:解析錯誤:語法錯誤,意外'<'

好。我的代碼看起來是這樣的,我的意思是wp_posts我的「自定義」查詢:

$results=$wpdb->get_results("SELECT * FROM `wp_posts` WHERE post_title LIKE '%$name_query%' OR post_content LIKE '%$instit_query%' OR post_content LIKE '%$spec_query%' OR post_content LIKE '%$zone_query%' ORDER by post_title"); 
$myposts = get_posts($result); 
foreach($result as $post) : setup_postdata($post); 
<li><a href="the_permalink()"> the_title() </a></li> 
endforeach; 
wp_reset_postdata(); 

我不認爲會做我想做的事情,所以我需要一些幫助,請,我怎麼能顯示的職位,我在$ results變量中查詢?

回答

1

爲了輸出html,您需要停止在輸出部分處理php,或者您需要將其作爲字符串回顯。

echo '<li><a href="' . get_the_permalink() . '"> ' . get_the_title() . ' </a></li>' 

foreach ($result as $post) { 
    setup_postdata($post); 
    ?><li><a href="<?php the_permalink() ?>"> <?php the_title() ?> </a></li><?php 
}