我有一个名为自定义的帖子类型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 Taxonomies有点问题......下面你可以看到我的自定义分类法的初始化命名job_keywords.
function register_job_keywords() {
$labels = array(
[... lables here ...]
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'job_keywords', array( 'job' ), $args );
}
Run Code Online (Sandbox Code Playgroud)
我也将它实现为自定义帖子类型job.
$args = array(
[...]
'taxonomies' => array( 'job_category' , 'job_keywords'),
'hierarchical' => false,
[...]
Run Code Online (Sandbox Code Playgroud)
在插件初始化我调用函数register_job_keywords(),它让我看到wp-admin中的关键字,我可以像标签等一样添加它们.所以一切正常在界面,我去我的PHP文件,并显示所有的分类.所以我得到了这个:
Array
(
[category] => …Run Code Online (Sandbox Code Playgroud) 我有一个wp模板,我想分配给一些页面.模板就是.显示与页面名称本身具有相同主类别名称的所有WooCommerce产品.
到目前为止,我已尝试使用此代码,但没有良好的输出:
$idObj = get_category_by_slug($pagename);
$id = $idObj->term_id;
echo ": ". $id;
Run Code Online (Sandbox Code Playgroud)
不幸的是,回声没有显示任何内容.
回应$pagename作品,并返回页面的slu ..
我有什么好办法让这个工作?
我想在每个产品的商店商店页面上显示我选择的一些特定产品属性.必须显示属性的名称并与其值相反.我开始编写代码,我想打印至少名称,但我只显示最后一个属性的名称
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) 我想要的是:修改 WooCommerce 搜索表单(在前端)的查询以通过搜索产品的名称、描述和产品标签来显示产品。
我所拥有的:我正在尝试使用受此答案启发的代码,该代码返回产品名称和描述的结果。但是,如果我使用标签名称进行搜索,则没有结果。搜索查询不搜索产品的标签。
如何重现此问题(将以下代码放在活动主题的 functions.php 文件中):
function search_product_by_tag( $search, &$query_vars ) {
global $wpdb, $pagenow;
if ( 'edit.php' == $pagenow || empty($search) ) {
return $search;
}
$args = array(
'posts_per_page' => -1,
'post_type' => 'product',
'meta_query' => array(
array(
'key' => 'taxonomy',
'value' => 'product_tag',
'field' => 'name',
'terms' => array($query_vars->query['s']),
'compare' => 'LIKE',
)));
$posts = get_posts( $args );
if ( empty( $posts ) ) return $search;
$get_post_ids = array();
foreach($posts …Run Code Online (Sandbox Code Playgroud) 我想在产品类别的后端表中添加一个新列。此列将包含一个链接“查看类别”,并将所有链接链接到 www.domain.com/category/category-name 页面。
我查看了 WordPress 文档,这是我想出的代码......但它不起作用!
function product_cat_cpt_columns($columns) {
$new_columns = array(
'Link' => "Link to page"
);
return array_merge($columns, $new_columns);
}
add_filter('manage_product_cat_posts_custom_columns' , 'product_cat_cpt_columns');
Run Code Online (Sandbox Code Playgroud)
知道我该怎么做吗?我真的很感谢你的帮助!
我只想更改特定类别的产品档案上的添加到购物车文本。例如,在预订类别上,我想要而不是add to cart文本,是Preorder. 我不知道如何在下面的函数中识别 Preorder 类别。
add_filter( 'add_to_cart_text', 'woo_archive_custom_cart_button_text' ); // < 2.1
function woo_archive_custom_cart_button_text() {
return __( 'Preorder', 'woocommerce' );
}
Run Code Online (Sandbox Code Playgroud) 我目前正在为 Woocommerce 网站开发主页,在此页面上的目标是让 3 行显示来自不同品牌的产品。例子; 第一排将展示苹果产品,第二排将展示三星产品,第三排将展示HTC产品。
我使用插件 CPT UI 创建自定义分类法“品牌”。现在我希望使用上面的示例仅显示特定品牌下列出的产品。
查看 Woocommerce Shortcodes,我看到了这个:
[products limit="8" columns="4" category="hoodies, tshirts" cat_operator="AND"]
Run Code Online (Sandbox Code Playgroud)
是否可以使用此案例品牌的自定义分类法来做这样的事情?IE:
[products limit="8" columns="4" brand="apple" cat_operator="AND"]
Run Code Online (Sandbox Code Playgroud)
任何在正确方向上的帮助或推动都非常感谢!
我的产品上有多种可变产品。https://alcocovers.com/shop/我面临的问题是:添加到购物车后,垃圾箱防水布在购物车页面上列出了项目数据,但产品Lugger Cover没有。这是一个屏幕截图:
我认为我在网站上使用的购物车项目数据模板存在一些问题,但我检查后发现没有任何问题(作为参考,这里是模板代码https://pastebin.com/fswKRZ8a)。我禁用了所有自定义模板,结果是相同的。我还仔细检查了这两种产品的设置方式是否完全相同,所以我不知道这背后的原因是什么。任何人都知道这会是什么原因造成的?
更新 #1:一位朋友建议,也许是因为 Lugger Cover 页面只有一个属性,这就是为什么它没有列出购物车上的商品数据。但我创建了一个测试页面,该页面也没有在购物车上列出商品数据...
更新 #2:我向测试页面添加了第三个属性,现在商品数据显示在购物车页面上。不知道为什么对于在产品页面上使用一个/两个属性的产品,项目数据不会显示在购物车上。我重新检查了模板文件,没有问题。
我有一个可以属于多个类别的产品,例如看一下以下字符串:
在 woocommerce 中,如果我有一个 ProductID,我可以执行以下操作:
function alg_product_categories_names2( $atts ) {
$product_cats = get_the_terms( $this->get_product_or_variation_parent_id( $this->the_product ), 'product_cat' );
$cats = array();
$termstest= '';
if ( ! empty( $product_cats ) && is_array( $product_cats ) ) {
foreach ( $product_cats as $product_cat ) {
if ( $term->parent == 0 ) { //if it's a parent category
$termstest .= ' PARENTCAT= '. $product_cat->name;
}
}
}
return htmlentities('<categories_names>'. $termstest .'</categories_names>');
}
Run Code Online (Sandbox Code Playgroud)
但这只是返回产品 …
custom-taxonomy ×10
wordpress ×10
php ×9
woocommerce ×8
product ×2
taxonomy ×2
arrays ×1
cart ×1
categories ×1
search ×1
shortcode ×1