我需要你帮助制作SQL
我拥有的:
自定义帖子类型(公司)
- 在分类法(类别)中,我在自定义分类法(节)的自定义字段(使用acf插件)上设置值。它存储在数据库中,如下所示:在wp\\U选项中,键:
{taxonomie}_{term_id}_{field_key}
, 值:section_term_id
. 例如,我有一个名为“婚礼花”的类别,id为15,含税。章节术语:“焊接”,id 14。因此,如果我这样做:get_option( \'category_15_section\' )
我去拿14
()_section
是字段键,可能是_aaa
或者其他,但我知道它会_section
)所以,我需要的是当我在cpt的归档页面上$_GET[\'section\']
变量(等于section term id == 14
) 我需要回显分类法(category)中的所有帖子,并且该类别必须具有custom-fied的值,该值在选项表中设置为$_GET[\'section\']
.
希望你能理解我需要什么,如果你不在评论中问我一些清晰的时刻。
迄今为止我的代码:
add_filter( \'pre_get_posts\', function( $query ) {
if( ! is_main_query() || ! is_post_type_archive() || ! $query->get( \'section\', false ) )
return $query;
$section = $query->get( \'section\' );
unset( $query->query[\'section\'] );
unset( $query->query_vars[\'section\'] );
$query->tax_query = false;
$query->set( \'tax_query\', false );
add_filter( \'posts_where\' , \'m7_24_section_posts_where\' );
//echo \'<pre>\'; var_dump( $query ); echo \'</pre>\';
return $query;
} );
function m7_24_section_posts_where( $where ) {
global $wpdb;
remove_filter( current_filter(), __FUNCTION__ );
$section = (int) $_GET[\'section\'];
//echo \'<pre>\'; var_dump( $where ); echo \'</pre>\';
// here i need to make sql to add categories wich have value in options table
// set up like $section
return $where;
}