i need your help in making SQL
What i have:
- custom post type ( company )
- taxonomie ( category ) applyed to cpt ( and has ct section select field )
- custom taxonomie ( section ) applyed to nothing
In taxonomie ( category ) i set value on custom field ( using acf plugin ) of custom taxonomie ( section ). and it stores in database like these:
in wp_options, key: {taxonomie}_{term_id}_{field_key}
, value: section_term_id
. For ex. i have category named "Wedding flowers" with id of 15 and tax. section term: "Weding" with id 14. So if i do: get_option( 'category_15_section' )
i'll get 14
( _section
is field key, it could be _aaa
or othere, but i for shore know that it will be _section
)
So, what i need is when i'm on archive page of cpt and i have $_GET['section']
variable ( wich is eaqual to section term id == 14
) I need to echo all posts in taxonomie ( category ), and that category must have value of custom fied wich has value in options table set up like $_GET['section']
.
Hope u understand what i need, if not ask some clearifying moments in comments.
my code so far:
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;
}