• こんにちは。

    カスタム投稿タイプでBOGOを使用するために、以下コードをfunctions.phpに追記しております。

    
     /*
     * @param array $localizable Supported post types.
     * @return array
     */
    function my_localizable_post_types( $localizable ) {
        $args = array(
            'public'   => true,
            '_builtin' => false
        );
        $custom_post_types = get_post_types( $args );
        return array_merge( $localizable, $custom_post_types );
    }
    add_filter( 'bogo_localizable_post_types', 'my_localizable_post_types', 10, 1 );

    一方、記事タイトルを日本語入力した際に、
    パーマリンクのスラッグを記事IDに変更する以下コードを記述しておりますが、
    関数my_localizable_post_types()を記述するとこれが動作しなくなります。

    function auto_post_slug( $slug, $post_ID, $post_status, $post_type ) {
    if ( preg_match( '/(%[0-9a-f]{2})+/', $slug ) ) {
    $slug = utf8_uri_encode( $post_type ) . '-' . $post_ID;
    }
    return $slug;
    }
    add_filter( 'wp_unique_post_slug', 'auto_post_slug', 10, 4 );

    パーマリンクに関する何らかの干渉が起こっているようなのですが、
    対応策などはございますでしょうか。

    対象のカスタム投稿は、Custom Post Type UIで作成しております。

    お詳しい方、ご教授いただけないでしょうか。
    宜しくお願い致します。

Viewing 1 replies (of 1 total)
  • 私も同様の問題が起こりましたので調べてみましたが「Bogo」のプラグイン自体有効にしたらwp_unique_post_slugは動作しないようです。

    プラグイン内のincludes/post.php内にpre_wp_unique_post_slugが使用されているのでwp_unique_post_slugの処理がスキップされているようですね。

    なので私の環境ではpre_wp_unique_post_slugを使うように以下のように修正することで動作しました。

    function auto_post_slug( $override_slug, $slug, $post_ID, $post_status, $post_type ) {
    if ( preg_match( '/(%[0-9a-f]{2})+/', $slug ) ) {
    $override_slug = utf8_uri_encode( $post_type ) . '-' . $post_ID;
    }
    return $override_slug;
    }
    add_filter( 'pre_wp_unique_post_slug', 'auto_post_slug', 10, 5 );
Viewing 1 replies (of 1 total)
  • The topic ‘カスタム投稿でスラッグを変更するコードが動作しない’ is closed to new replies.