2012-10-06 3 views
1

코드의 this snippet쿼리 모든 워드 프레스 포스트 제목

를 사용하여 제안하고 현재는 모든 태그를 검색하고, 나는 단지 포스트의 제목을 검색 할. 어떤 도움을 주셔서 감사합니다.

이것은 모든 게시물에 대한 수정이 필요로하는 모든 태그를 호출하는 SQL 쿼리입니다.

<?php global $wpdb; 
$search_tags = $wpdb->get_results("SELECT name from wp_terms WHERE name LIKE '$search%'"); 
foreach ($search_tags as $mytag) 
    { 
    echo $mytag->name. " "; 
    } 
    ?> 

답변

2

직접 모든 게시물 제목

// The Query 
query_posts('posts_per_page=-1'); 

// The Loop 
while (have_posts()) : the_post(); 
    echo '<li>'; 
    the_title(); 
    echo '</li>'; 
endwhile; 
+2

감사처럼 jQuery 플러그인을 통해 페이지를 호출해야 쉽게 얻을 그러나 나는 내가 원하는 것을 달성하기 위해 쿼리를 수정했습니다. 희망이 다른 사람들을 도울 수 있습니다. ?

'code' get_results ("wp_posts에서 post_title을 선택하십시오 어디에서 post_title LIKE '$ search %'"); foreach ($ search_tags를 $ mytag로) {echo $ mytag-> post_title. ""; }?>'code' –

+1

@JunaidHassan Ok :) – GBD

3

나는 워드 프레스 테마에 어떤 요청을해야했던이 일을 얻기 위해 워드 프레스에서 빌드 기능을 사용할 수 있습니다. 귀하의 경우 (제목을 얻는 것이 태그를 얻는 것보다 쉽게 ​​할 수 있습니다, 예제 링크 에서처럼) 물건을 더 쉽게 할 수 있습니다 (아마).

은 첫째로 당신은 게시물을 얻을 수있는 PHP 페이지를 확인해야합니다. 당신은 아마 알다시피 당신은 독립 PHP 파일에서 WP 물건을 사용할 수 없습니다, 그래서 당신의 파일은 내가 당신을 도우려고 몇 가지 의견을 추가

<?php 
    // Include the file above for being able to use php stuff 
    // In my case this file was in a folder inside my theme (my_theme/custom_stuff/get_posts.php). 
    // According to this file position you can modify below path to achieve wp-blog-header.php from wp root folder 
    include('../../../../wp-blog-header.php'); 

    // Get all published posts. 
    $list_posts = get_posts(array('numberposts' => -1)); 

    // Get "q" parameter from plugin 
    $typing = strtolower($_GET["q"]); 

    //Save all titles 
    $list_titles = array(); 
    foreach($list_posts as $post) { $list_titles[] = $post->post_title; } 

    // To see more about this part check search.php from example 
    foreach($list_titles as $title) { 
    if(strpos(strtolower($title), $typing)){ 
     echo $title; 
    } 
    } 

?> 

처럼 보일 것이다 (get_posts.php가 부르 자) 보다 나은.

이제 물건 만 @GBD 많은 감사

$('#yourInput').autocomplete("path_to/get_posts.php");