没有在WordPress中按标题发布

时间:2019-06-22 11:17:06

标签: php wordpress

我必须尝试使用​​belove代码才能按标题获取帖子,但我无法获取帖子

<FilesMatch>

这给了我一个空的响应,有些给了我所有的帖子列表

3 个答案:

答案 0 :(得分:4)

尝试按wpdb类检索帖子,如下所示:

global $wpdb;
$myposts = $wpdb -> get_results($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_title LIKE '%s'", '%'. $wpdb->esc_like($title) .'%'));

foreach ($myposts as $mypost) 
{
    $post = get_post($mypost);

    // add your code here for a post processing

}

答案 1 :(得分:0)

尝试以下操作。

$args = array('s' => 'Gallery','posts_per_page' => -1);

$your_searchposts = get_posts($args);

OR

$args = array('s' => 'Gallery','posts_per_page' => -1,'post_status'=>'any');

$your_searchposts = get_children($args);

答案 2 :(得分:0)

您可以通过以下代码获取帖子:

$args = array("post_type" => "mytype", "s" => $title);
$query = get_posts( $args );