查询所有字preSS文章标题 [英] Query all wordpress post titles

查看:116
本文介绍了查询所有字preSS文章标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Word preSS自动建议使用的的code这个片段

和目前正在搜索的所有标签,我希望它仅搜索文章标题。任何帮助是AP preciated。

这是SQL查询调用所有需要修改的所有帖子的标签。

 < PHP全局WPDB $;
 $ search_tags = $ wpdb-> get_results(从wp_terms SELECT name其中name LIKE'$搜索%');
 的foreach($ search_tags为$ MyTag的)
   {
     回声$ mytag->的名字。 ;
   }
  ?>
 

解决方案

这些天,我不得不做一个字preSS主题的一些要求。 在你的情况(获得冠军可以比获得标签来实现更容易,因为在你的榜样链接)的东西,可以做更容易(我猜)。

首先你必须做出一个PHP页面来获得职位。正如你可能知道你将无法使用WP的东西,在独立的PHP文件,使您的文件(让我们把它叫做 get_posts.php )看起来像

 < PHP
  //包含上述文件为能够使用PHP的东西
  //在我的情况下,这个文件是我的主题(my_theme / custom_stuff / get_posts.php)内的文件夹中。
  //根据该文件的位置,你可以修改下面的路径来实现WP-博客 - 的header.php通过WP根文件夹
  包括('../../../../wp-blog-header.php');

  //获取所有已发布的帖子。
  $ list_posts = get_posts(阵列('numberposts'=​​ -1)〜);

  //获取Q的插件参数
  $打字=用strtolower($ _ GET [Q]);

  //保存所有冠军
  $ list_titles =阵列();
  的foreach($ list_posts为$后){$ list_titles [] = $后> POST_TITLE; }

  //要了解更多有关的例子这部分检查的search.php
  的foreach($ list_titles为$标题){
    如果(strpos(用strtolower($标题),$打字)){
      回声$称号;
    }
  }

?>
 

我加了一些意见尽力帮助你更好。

现在得到的东西很容易,你只需要通过调用jQuery插件页面像

  $('#yourInput')自动完成(path_to / get_posts.php)。
 

I am using Wordpress auto suggests using this snippet of code

and currently it is searching all tags, I want it to search only post titles. Any help is appreciated.

This is sql query calling all the tags which needs to be modified for all posts.

 <?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. " "; 
   }
  ?>

解决方案

These days i had to do some request in a wordpress theme. In your case ( getting title can be done easier than getting tags, as in your example link ) the stuff can be done easier (i guess).

Firstly you have to make a php page to get posts. As you maybe know you won't be able to use wp stuff in standalone php files, so your file ( let call it get_posts.php ) will look like

<?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;
    }
  }

?>

I added some comments trying to help you better.

Now stuff get easy, you only have to call your page through jQuery plugin like

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

这篇关于查询所有字preSS文章标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆