首页 > 解决方案 > 仅获取 slug 自定义分类的可变部分

问题描述

在我的主页上,我编写了一个查询来显示分类中的所有元素 (jobpost_job_type) 我想将它们链接到存档页面,但调整搜索的 url 以便显示正确的结果。

$args = array(
    'hide_empty' => false
);
$taxonomy = 'jobpost_job_type';
$terms = get_terms($taxonomy, $args);
$terms_count = $terms->count;

?>
<div class="jobs__types--wrapper">
    <?php if ( $terms && !is_wp_error( $terms ) ) { ?>
        <?php foreach ( $terms as $term ) { ?>
            <a class="jobs__types--item" href="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; echo get_term_link($term->slug, $taxonomy); ?><span> (<?php echo $term->count; ?>)</span></a>
        <?php } ?>
    <?php } ?>
    <a class="jobs__types--item" href="">Spontaan solliciteren</a>
    <a class="jobs__types--item" href="">Werken bij ons</a>
    <a class="jobs__types--item" href="">Andere</a>
</div>

现在链接的网址是:https ://ago.staging.dfib.net/vacatures-type/maintenance-engineering/ 我想将其更改为:https ://ago.staging.dfib.net/vacatures /?search_keywords=&selected_jobtype=维护工程&selected_location=-1

我怎样才能从 slug 中获取“维护工程师”并在我需要的 url 中使用?

标签: phpwordpresscustom-post-type

解决方案


推荐阅读