标签: custom-taxonomy

Wordpress:查询帖子没有分配分类

我想通过自定义分类法的特定术语(由URL指定)过滤所有帖子查询.目前我正在使用add_filter('request',...)和'tax_query',现在这种方式有效.

所以我得到了这个学期的所有帖子,但是我想获得这些帖子,这些帖子没有分配这个分类的任何条款.

我在尝试这样的事情:

$request['tax_query'] = array(
    'relation' => 'OR',
    array(
        'taxonomy' => 'brand',
        'field' => 'slug',
        'terms' => array( $term )
    ),
    array(
        'taxonomy' => 'brand',
        'field' => 'slug',
        'terms' => NULL,
        'operator' => 'IS'
    ),
);
Run Code Online (Sandbox Code Playgroud)

但是,由于Wordpress不支持"IS"或"IS NULL",因此也不起作用.

那么,任何想法如何查询一个术语和帖子的帖子没有一个术语?

编辑:另一个解决方案是查询所有条款,然后在tax_query中排除它.但是我想保存这个查询.

wordpress posts custom-taxonomy

5
推荐指数
1
解决办法
1062
查看次数

在自定义帖子类型管理页面上显示自定义分类的列

我想在我的自定义帖子类型管理窗口中添加一列来显示我的自定义分类.

@SarthakGupta提供的这个解决方案为我创建了这个列,但是既没有分类也没有回应"No taxonomy set"消息: 在自定义帖子类型列表中显示自定义分类列

我已经看到其他地方发布过类似的解决方案,对空分类专栏提出了类似的抱怨.

可能导致问题的原因是什么?是否有可能此解决方案不适用于WordPress 3.3?

谢谢.

wordpress custom-post-type custom-taxonomy

5
推荐指数
2
解决办法
9651
查看次数

Get All Shipping Classes in Woocommerce 3

I've been unable to crack this nut, but can't help feel that I'm missing something simple.

I'm developing a WooCommerce plugin that should provide a list of shipping classes on its admin settings page. The following code as suggested in another question's answer indicated that the following should work:

$shipping           = new \WC_Shipping();
$shipping_classes   = $shipping->get_shipping_classes();
var_dump($shipping_classes);
die();
Run Code Online (Sandbox Code Playgroud)

Unfortunately the output is an empty array.

I am using Wordpress 4.9.5 and WooCommerce 3.3.5. Thanks for any help!

UPDATE I have …

php wordpress shipping custom-taxonomy woocommerce

5
推荐指数
1
解决办法
2538
查看次数

在 Woocommerce 中以编程方式添加新产品类别

我正在开发一个 Wordpress 网站,并且正在使用 Woocommerce,我有很多产品类别,我想将它们添加到代码中,而不是添加到 Wordpress CMS 本身中。

有谁知道我如何进入可以添加类别的代码。我到处都找过了,即使在数据库中也找不到它。我还想更改代码中的菜单,因为这也会减少很多工作。

任何帮助表示赞赏。

php database wordpress custom-taxonomy woocommerce

5
推荐指数
1
解决办法
5161
查看次数

在 Woocommerce 的 WP_query 中获取目录中可见的产品

我目前正在尝试获取目录中可见的类别页面中的所有产品。我在这里试过这个,但我没有得到这个查询的产品:

$args = array(
    'post_type'   => 'product',
    'product_cat' => get_queried_object()->slug,
    'meta_query'  => array(
        array(
            'key'     => '_visibility',
            'value'   => array( 'catalog', 'visible' ),
            'compare' => 'IN',
        )
    )
);
$loop = new WP_Query( $args );

var_dump( $loop );
Run Code Online (Sandbox Code Playgroud)

当我删除meta_query可见性部分时,我将获得所有产品,包括隐藏的产品,但我只需要可见的产品。这里有什么问题?

php wordpress product custom-taxonomy woocommerce

5
推荐指数
1
解决办法
2652
查看次数

更改 WooCommerce 中的“选择选项”变体下拉标签

我尝试将“选择选项”的值更改为属性名称。因此,在您可以选择颜色的下拉列表中,它应该是名称颜色作为第一个颜色。到目前为止,它可以使用此代码片段

add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'cinchws_filter_dropdown_args', 10 );

function cinchws_filter_dropdown_args( $args ) {
    $var_tax = get_taxonomy( $args['attribute'] );
    $args['show_option_none'] = apply_filters( 'the_title', $var_tax->labels->name );
    return $args;
}
Run Code Online (Sandbox Code Playgroud)

我现在遇到的问题是它显示“产品颜色”或“产品材质”,因此它在属性值之前添加了产品。如何只获取属性值?

下拉字段

php wordpress custom-taxonomy woocommerce

5
推荐指数
1
解决办法
4967
查看次数

按自定义分类ID查询帖子

我有一个名为自定义的帖子类型portfolio和一个名为build-type(作为类别)的自定义分类

我正在尝试portfolio通过build-typeID 查询帖子,例如"酒店"中的所有投资组合帖子(对于该分类,id = 4)

// gets the ID from a custom field to show posts on a specific page   
$buildType = get_post_meta($post->ID, 'build_type_id', true);
// run query
query_posts(array( 
    'post_type' => 'portfolio',
    'showposts' => -1,
    'tax_query' => array(
        'taxonomy' => 'build-type',
        'terms' => $buildType,
        'field' => 'term_id'
    ),
    'orderby' => 'title',
    'order' => 'ASC'
));
Run Code Online (Sandbox Code Playgroud)

目前它正在调用所有 portfolio帖子,而不仅仅是那些有build-typeID的帖子

对于'field' => 'term_id'我应该使用term_id,tag_ID,id或其他什么东西? …

wordpress taxonomy custom-taxonomy

4
推荐指数
1
解决办法
4万
查看次数

Wordpress,在存档页面中获取当前的分类级别

我正在创建一个 WordPress 站点,以使用自定义帖子类型和自定义分层分类法显示项目目录。我想保持简单并处理单个存档页面中的项目,但我需要帮助如何确定当前显示的分类级别。基本上,我需要以下功能:

if ($current_term_level = 0) {
    // show first drop-down
} else if ($current_term_level = 1) {
    // show second drop-down
} else {
    // show third drop-down
}
Run Code Online (Sandbox Code Playgroud)

有人可以解释如何$current_term_level输出适当的值吗?

php wordpress taxonomy custom-taxonomy

4
推荐指数
1
解决办法
3472
查看次数

按名称获取WooCommerce类别的ID

我有一个wp模板,我想分配给一些页面.模板就是.显示与页面名称本身具有相同主类别名称的所有WooCommerce产品.

到目前为止,我已尝试使用此代码,但没有良好的输出:

$idObj = get_category_by_slug($pagename);
$id = $idObj->term_id;
echo ": ". $id;
Run Code Online (Sandbox Code Playgroud)

不幸的是,回声没有显示任何内容.
回应$pagename作品,并返回页面的slu ..

我有什么好办法让这个工作?

php wordpress categories custom-taxonomy woocommerce

4
推荐指数
1
解决办法
8758
查看次数

在Woocommerce存档页面上显示特定的产品属性

我想在每个产品的商店商店页面上显示我选择的一些特定产品属性.必须显示属性的名称并与其值相反.我开始编写代码,我想打印至少名称,但我只显示最后一个属性的名称

add_action('woocommerce_after_shop_loop_item','add_attribute');
function add_attribute() {
    global $product;
    $weigth_val = $product->get_attribute('weight');
    $quant_val = $product->get_attribute('quantity');
    $length_val = $product->get_attribute('length');
    echo $weigth_val;
    echo $quant_val;
    echo $length_val;
}
Run Code Online (Sandbox Code Playgroud)

php wordpress product custom-taxonomy woocommerce

4
推荐指数
1
解决办法
3230
查看次数