我提出了一个解决方案,该解决方案无需通过PHP构建完整的确认。这并不适用于每个人的情况,但因为我确实构建了自己的函数/短代码,所以它对我很有用。
我将条件逻辑添加到我的短代码中,并删除了GF短代码。为此,我添加了merge\\u标记和值参数,如下所示:
[useful-tools type="documents" desc="true" merge_tag="{:3:value}" value="B"]
对于那些想看到我的短代码的人,我会把它包括在这里。它设置为列出与自定义分类法匹配的所有自定义帖子类型。还可以通过删除参数,将它们列在GF之外。
function useful_tools_list($atts){
$atts = shortcode_atts(
array(
\'type\' => \'\',
\'desc\' => \'\',
\'ul\' => \'\',
\'li\' => \'\',
\'merge_tag\' => \'\',
\'value\' => \'\',
),
$atts
);
$results = \'\';
if (($atts[\'merge_tag\']) && (!preg_match(\'/\\b\'.$atts[\'value\'].\'\\b/\', $atts[\'merge_tag\']))) {
$results .= \'\';
} else {
$all_terms = get_terms(\'types\');
foreach($all_terms as $term) {
wp_reset_query();
if (($atts[\'type\']) && ($atts[\'type\'] != "")) {
$args = array(\'post_type\' => \'useful-tools\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'types\',
\'field\' => \'slug\',
\'terms\' => $term->slug,
),
),
\'types\' => $atts[\'type\'],
);
} else {
$args = array(\'post_type\' => \'useful-tools\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'types\',
\'field\' => \'slug\',
\'terms\' => $term->slug,
),
),
);
}
$loop = new WP_Query($args);
if($loop->have_posts()) {
if ((!$atts[\'type\']) || ($atts[\'type\'] == "")) {
$results .= \'<h2>\'.$term->name.\'</h2>\';
}
if (($atts[\'ul\']) && ($atts[\'ul\'] == "true")) {
$results .= \'<ul class="tools-type-ul">\';
}
while($loop->have_posts()) : $loop->the_post();
$postID = get_the_ID();
$desc = \'\';
$actualDesc = get_post_meta($postID, \'_post_desc\', true);
if ($atts[\'desc\'] == \'true\' && $actualDesc != \'\') {
$desc = \' - \'.get_post_meta($postID, \'_post_desc\', true);
}
if (($atts[\'li\']) && ($atts[\'li\'] == "true")) {
$results .= \'<li><a href="\'.get_post_meta($postID, \'_post_url\', true).\'">\'.get_the_title().\'</a>\'.$desc.\'</li>\';
} else {
$results .= \'<a href="\'.get_post_meta($postID, \'_post_url\', true).\'">\'.get_the_title().\'</a>\'.$desc.\'<br>\';
}
endwhile;
if (($atts[\'ul\']) && ($atts[\'ul\'] == "true")) {
$results .= \'</ul>\';
}
}
}
}
return $results;
}
add_shortcode(\'useful-tools\', \'useful_tools_list\');