【问题标题】:WordPress post title query is not working with special characterWordPress 帖子标题查询不适用于特殊字符
【发布时间】:2017-07-06 19:40:55
【问题描述】:

此标题查询不起作用,其中帖子标题在标题前有一个特殊字符。我检查了他的标题。例如:-y-

这里是帖子单页模板的代码:

<?php

$get_s_value = $_GET['search'];

if ($get_s_value == 'true') {

    $current_p_title = get_the_title();

    $args = array (
        'post_type'   => 'trending',
        'post_status' => 'publish',
        "s"           => $current_p_title,
    );

    query_posts($args);

    if (have_posts()): the_post();

        $sahifa_trending_count = get_post_meta(get_the_ID(), '_trending_count', 1);
        $update_count          = $sahifa_trending_count + 1;
        $last_m_date           = get_the_modified_date('Y-m-d');
        $trending_c_date       = date('Y-m-d');

        if ($last_m_date = $trending_c_date) {

            update_metadata('post', get_the_ID(), '_trending_count', $update_count);
        } else {
            update_metadata('post', get_the_ID(), '_trending_count', '1');
        }

    else:

        $create_post = array (
            'post_type'   => 'trending',
            'post_title'  => get_the_title(),
            'post_status' => 'publish',
            'meta_input'  => array (
                '_trending_count' => '1',
            ),
        );

        wp_insert_post($create_post);


    endif;
    wp_reset_query();
}

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    请尝试对标题进行编码。

    $create_post = array (
                'post_type'   => 'trending',
                'post_title'  => utf8_encode(get_the_title()),
                'post_status' => 'publish',
                'meta_input'  => array (
                    '_trending_count' => '1',
                ),
            );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-27
      • 2014-08-09
      • 2016-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多