Skip to content

Instantly share code, notes, and snippets.

@ko31
Last active June 28, 2019 12:41
Show Gist options
  • Select an option

  • Save ko31/54ad1dd3b58cf6d0cf53526f6f480766 to your computer and use it in GitHub Desktop.

Select an option

Save ko31/54ad1dd3b58cf6d0cf53526f6f480766 to your computer and use it in GitHub Desktop.
WP Show Posts のデータ表示条件を PHP から変更するサンプル
<?php
/**
* WP Show Posts のデータ表示条件を PHP から変更するサンプル
*/
add_filter( 'wpsp_settings', function( $settings ) {
// 検索対象をカテゴリーにする
$settings['taxonomy'] = 'category';
// 検索条件を AND にする
$settings['tax_operator'] = 'AND';
// 'gunma-hotel' というページの場合
if ( is_page( 'gunma-hotel' ) ) {
// gunma, hotel カテゴリーの両方が選択されているデータを取得
$settings['tax_term'] = 'gunma, hotel'; // 半角スペースも含めるよう注意
// 'gunma-restaurant' というページの場合
} else if ( is_page( 'gunma-restaurant' ) ) {
// gunma, restaurant カテゴリーの両方が選択されているデータを取得
$settings['tax_term'] = 'gunma, restaurant';
// 'xxxxx' というページの場合
} else if ( is_page( 'xxxxx' ) ) {
// aaa, bbb, ccc カテゴリーが選択されているデータを取得
$settings['tax_term'] = 'aaa, bbb, ccc';
}
return $settings;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment