我有一个CPT的库存,我试图显示所有制造商的下拉列表。我有form和pre\\u get\\u posts功能,这样当用户选择一个制造商时,页面会刷新并仅显示该制造商的库存。
问题是:一旦选择了制造商。页面刷新,只有mfr显示为选项!无论我如何构建选择选项(我不会将它们全部发布在这里,因为我已经尝试了10个不同的循环),我都无法让它显示所有MFR。总是
我已经阅读了几十篇文章(字面意思),似乎找不到有效的解决方案。
以下是我现在拥有的:
功能。PHP
function my_pre_get_posts( $query ) {
    // do not modify queries in the admin
    if( is_admin() ) {
        return $query;      
    }
    // only modify queries for \'inventory\' post type
    if( isset($query->query_vars[\'post_type\']) && $query->query_vars[\'post_type\'] == \'inventory\' ) {
        
        // allow the url to alter the query
        if( isset($_GET[\'item_oem\']) ) {
            $query->set(\'meta_key\', \'item_oem\');
            $query->set(\'meta_value\', $_GET[\'item_oem\']);
            $query->set( \'meta_compare\', \'=\' );
        } 
    }
    // return
    return $query;
}
add_action(\'pre_get_posts\', \'my_pre_get_posts\');
 回路:
        <?php // using get right now to see the query string and confirm functionality ?> 
        <form method="get" action="" onchange="submit();">
            <?php 
                $posts = get_posts( array(
                \'post_type\' => \'inventory\',
                \'posts_per_page\' => -1,
                \'orderby\' => \'date\',
                \'order\' => \'DESC\',
            ));
            if ( $posts ): ?>
            <select name="item_oem" id="select-oem">
                <?php foreach( $posts as $post ): ?>
                    <option value="<?php the_field(\'item_oem\'); ?>"> <?php the_field(\'item_oem\'); ?> </option>
                <?php endforeach; ?>
            </select>
        <?php endif; ?>
        <?php wp_reset_postdata(); ?>
        </form>
 所以,这确实给了我一个完整的制造商列表。但是,一旦您选择一个,它就会重新加载页面,只显示该制造商的库存。,则选定的Mfr是选择中的唯一选项。
我如何覆盖它并始终显示“item\\u oem”元键的所有元值??
非常感谢!