$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp query - Filter Custom post type by another Custom post type|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp query - Filter Custom post type by another Custom post type

matteradmin9PV0评论

Assume, i have two custom post types - Project and Technology. Every project has a relation to Technology (using ACF). The question is - How to filter it by Technology. I tried this approach:

'post_type' => 'project',
'meta_query'    => array(
'relation' => 'AND',
    array(
        'key' => 'technology',
        'value' => $_GET['technology'],
        'compare' => 'LIKE',
    ),
    array(
        'key' => 'country',
        'value' => $_GET['country'],
        'compare' => 'LIKE',
    )
)

But it works only for simple relations (like string, int or bool), but i doesn't work with object relations.

Assume, i have two custom post types - Project and Technology. Every project has a relation to Technology (using ACF). The question is - How to filter it by Technology. I tried this approach:

'post_type' => 'project',
'meta_query'    => array(
'relation' => 'AND',
    array(
        'key' => 'technology',
        'value' => $_GET['technology'],
        'compare' => 'LIKE',
    ),
    array(
        'key' => 'country',
        'value' => $_GET['country'],
        'compare' => 'LIKE',
    )
)

But it works only for simple relations (like string, int or bool), but i doesn't work with object relations.

Share Improve this question asked Dec 26, 2016 at 14:40 Alex SanzharevskyyAlex Sanzharevskyy 1 3
  • What is the common relation between the two post types? The same post meta? – Jami Gibbs Commented Dec 26, 2016 at 16:53
  • i don't understand your question((( i created custom post types with CTP UI, and connected those with ACF. – Alex Sanzharevskyy Commented Dec 26, 2016 at 18:01
  • How does ACF store relationship? This is probably something you will have to ask ACF support, as it is specific to that plugin. – Milo Commented Dec 26, 2016 at 18:29
Add a comment  | 

1 Answer 1

Reset to default -1

Get the two post types along with their acf meta and use PHP Array Functions ( like Array Interset) to get the common/union or intersection. Additionally this will help you in this regards.

Post a comment

comment list (0)

  1. No comments so far