我必须创建一个搜索表单,在其中必须按自定义帖子类型的状态填充选择。其中一些具有相同的状态,然后我想进行分组以获得一个干净的状态选择列表..我已经这样做了:
<?php
function query_group_by_filter($groupby){
global $wpdb;
return $wpdb->postmeta.".meta_key = 'state'";
}
?>
<?php add_filter('posts_groupby', 'query_group_by_filter'); ?>
<?php $states = new WP_Query(array('post_type' => 'observatoire')); ?>
<?php remove_filter('posts_groupby', 'query_group_by_filter'); ?>
<select id="" class="" name="siege_pays" >
<option value=""></option>
<?php
while ( $states->have_posts() ) : $states->the_post();
echo "<option value=".get_field_object('state').">".get_field_object('state')."</option>";
endwhile;
?>
</select>
Run Code Online (Sandbox Code Playgroud)
结果查询不起作用..请帮忙:)
'SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'observatoire' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') OR wp_posts.post_status = 'private') GROUP BY wp_postmeta.meta_key = 'siege_pays' ORDER BY wp_posts.post_date …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 JIRA 中使用一些 AUI - 在用 JAVA 编写的我自己的自定义字段的编辑模式下。我找到了这个页面: https: //docs.atlassian.com/aui/latest/sandbox/#,将来我想使用设置一个示例 Auiselect2。
https://docs.atlassian.com/aui/5.5.1/docs/auiselect2.html - 这里写的是,这只是实验性的,那么我应该执行哪些步骤来使用它?在下面的示例中,您可以看到,我试图添加此功能,但它简单地不起作用。我正在使用文档中提到的示例 -
编辑.vm:
$webResourceManager.requireResource("cz.firma.rozy:zakaznik")
<form class="aui">
<select id="select2-example" multiple>
<option value="CONF">Confluence</option>
<option value="JIRA">JIRA</option>
<option value="BAM">Bamboo</option>
<option value="JAG">JIRA Agile</option>
<option value="CAP">JIRA Capture</option>
<option value="AUI">AUI</option>
</select>
</form>
Run Code Online (Sandbox Code Playgroud)
和 zakaznik.js
AJS.$(function() {
AJS.$("#select2-example").auiSelect2();
});
Run Code Online (Sandbox Code Playgroud)
我的 atlassian-plugin.xml 是:
<web-resource key="zakaznik-resources" name="zakaznik Web Resources">
<dependency>com.atlassian.auiplugin:ajs</dependency>
<dependency>com.atlassian.auiplugin:jquery</dependency>
<dependency>com.atlassian.auiplugin:jquery-ui-other</dependency>
<dependency>com.atlassian.auiplugin:aui-select2</dependency>
<context>atl.general</context>
<context>atl.admin</context>
<resource type="download" name="zakaznik.css" location="/css/zakaznik.css"/>
<resource type="download" name="zakaznik.js" location="/js/zakaznik.js"/>
<resource type="download" name="images/" location="/images"/>
<context>zakaznik</context>
</web-resource>
...
<customfield-type name="Pridani zakaznika" i18n-name-key="customer-add.name" key="customer-add" class="cz.firma.rozy.jira.customfields.CustomerCustomField"> …Run Code Online (Sandbox Code Playgroud) 当我尝试在 JIRA 中的自定义字段上设置值时遇到问题,它返回此错误:
File "c:\python27\lib\site-packages\jira\resilientsession.py", line 45, in raise_on_error
r.status_code, error, r.url, request=request, response=r, **kwargs)
JIRAError: JiraError HTTP 400
text: Operation value must be a string
url: http://iasp091x.ia.ro.conti.de:8080/rest/api/2/issue/31424
response headers = {'X-AUSERNAME': 'continental', 'X-ASEN': 'SEN-5132028', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked', 'X-Seraph-LoginReason': 'OK', 'Vary': 'User-Agent', 'X-AREQUESTID': '850x418015x3', 'X-ASESSIONID': 'gv7hra', 'Connection': 'close', 'Cache-Control': 'no-cache, no-store, no-transform', 'Date': 'Mon, 01 Feb 2016 12:10:49 GMT', 'Server': 'Apache-Coyote/1.1', 'Content-Type': 'application/json;charset=UTF-8'}
response text = {"errorMessages":[],"errors":{"customfield_11301":"Operation value must be a string"}}
Run Code Online (Sandbox Code Playgroud)
我使用的代码是这样的:
new_issue = jira.create_issue(project='PT', summary=issue_summary, …Run Code Online (Sandbox Code Playgroud) 在我的设计中,我有非标准的计费字段标签和标记。例如“Town / City *”应该是“Province *”。
我使用过 WOO 文档和 filter woocommerce_billing_fields。它适用于类名、占位符、创建新字段。但我无法触及已更改的标签。
$out_arr['billing_city']['class'][0] = 'form-row-first';
$out_arr['billing_city']['label'] = __('Province', 'woocommerce');
$out_arr['billing_postcode']['label'] = __('Zipcode', 'woocommerce');
Run Code Online (Sandbox Code Playgroud)
并使用var_dump新$out_arr数组显示正确的标签
["billing_city"]=>
array(4) {
["label"]=>
string(8) "Province"
["required"]=>
bool(true)
["class"]=>
array(2) {
[0]=>
string(14) "form-row-first"
[1]=>
string(13) "address-field"
}
["autocomplete"]=>
string(14) "address-level2"
}
Run Code Online (Sandbox Code Playgroud)
但我在前端仍然有旧标签。请问有什么建议吗?
我正在使用高级自定义字段插件和自定义帖子类型 UI 为我的用户提供一些额外的功能。我遇到的问题是我设置了一个用户信息菜单,并且在列表视图中所有新帖子都显示为自动草稿。无论如何,我可以让字段公司名称作为列表视图的帖子标题吗?
我尝试了下面的代码,但它没有将公司名称更新为帖子标题,并且在自定义帖子页面中它显示诸如“您当前正在编辑显示最新帖子的页面”之类的消息。
我的示例代码:
add_filter('title_save_pre', 'save_title');
function save_title() {
if ($_POST['post_type'] == 'users') : // my custom post type name
$new_title = $_POST['company_name']; // my custom field name
$my_post_title = $new_title;
endif;
return $my_post_title;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试按价格显示服务列表。我已经设置了自定义帖子类型和自定义字段等。但是,当我在页面上运行查询时,最昂贵的服务(100 英镑)首先显示而不是最后显示......我编写的查询如下:
$services = new WP_Query(array(
'post_type' => 'service',
'tax_query' => array(
array(
'taxonomy' => 'service_type',
'field' => 'name',
'terms' => $post->post_name,
),
),
'meta_key' => 'price',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'meta_value_num',
'order' => 'ASC', ));
Run Code Online (Sandbox Code Playgroud)
该页面的链接是dev.poshwashlondon.co.uk/valeting。
提前致谢!
在 WooCommerce 中,当我提交时,如何捕获在订单编辑管理页面中添加的自定义选择字段?
我在文件中添加了这个自定义选择字段class-wc-meta-box-order-data.php。我明白了:
但我不知道如何捕捉或拯救 $_POST['vendor']
我尝试添加$_POST['vendor']的wp-admin/post.php?但它不起作用。
这是我添加的代码:
<select class="wc-customer-search" id="customer_user" name="customer_user" data-placeholder="<?php esc_attr_e( 'Guest', 'woocommerce' ); ?>" data-allow_clear="true">
<option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo htmlspecialchars( $user_string ); ?></option>
</select>
<!--/email_off-->
</p>
<p> <label for="order_status">???? </label>
<select name="vendor">
<?php
global $wpdb;
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
for($i=1;$i<=$user_count;$i++){
$user_info = get_userdata($i);
if (implode(', ', $user_info->roles)=='vendor')
echo "<option value=".$user_info->user_login.">$user_info->user_login</option>";
}
?>
</select></p>
Run Code Online (Sandbox Code Playgroud)
如何获取提交的值以及如何保存它?
我尝试在 woocommerce搜索中包含自定义字段值,但遇到问题。
在 Google 和 Stack 上,我也看到了带有 pre_get_posts 的示例,所以我认为这是一个很好的方向,我编写了如下代码:
function custom_search( $query ) {
if( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_search() ) {
$meta_query = array(
'key' => 'custom_color',
'value' => $query->query['s'],
'compare' => 'LIKE'
);
$query->set( 'meta_query', $meta_query );
}
}
}
add_action( 'pre_get_posts' , 'custom_search' );
Run Code Online (Sandbox Code Playgroud)
不幸的是它不起作用。你能帮助我吗?
我正在使用 woocommerce,我想不仅通过默认的内置到期日期检查来验证优惠券,还想验证到期时间。
我为优惠券添加了一个自定义字段,允许设置到期时间。
我编写了以下代码片段以覆盖validate_coupon_expiry_date类 WC_Discounts 中的默认方法:
class WC_My_plugin_Discounts extends WC_Discounts
{
// override validate_coupon_expiry_date to include expiry time:
protected function validate_coupon_expiry_date($coupon)
{
$expiry_date = date('Y-m-d', $coupon->get_date_expires()->getTimestamp());
// I add a custom field `expiry_time` in postmeta table:
$expiry_time = $coupon->get_meta('expiry_time');
$dateTime = new DateTime($expiry_date . $expiry_time);
if ($coupon->get_date_expires() && apply_filters('woocommerce_coupon_validate_expiry_date', time() > $dateTime, $coupon, $this)) {
throw new Exception(__('This coupon has expired.', 'woocommerce'), 107);
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我尝试使用以下代码段验证优惠券:
add_filter('woocommerce_coupon_is_valid', array($this, 'validate_coupon'), 15, 2);
function validate_coupon($valid, $coupon)
{ …Run Code Online (Sandbox Code Playgroud) 我试图在 woocommerce 结帐顶部放置两个自定义字段(理想情况下是购物车页面,但我在网上找不到任何有关此操作的信息)
我已经在结帐页面上显示了两个自定义字段,但由于 php 知识非常有限,我尝试创建一个下拉菜单等。从表面上看,一切似乎都很好。这些字段显示在结账页面上,但每当我输入信息并尝试继续执行订单以测试这些值是否显示在感谢页面和电子邮件上时,系统都会要求我在这些必填字段中填写信息。由于某种原因,页面无法识别字段为空
我用了这篇文章...https://www.businessbloomer.com/woocommerce-add-custom-checkout-field-php/
但我必须对其进行大量编辑才能达到这一点。我确信有很多错误。
add_action('woocommerce_before_checkout_form', 'custom_add_custom_checkout_fields');
function custom_add_custom_checkout_fields($checkout)
{
echo '<h3>Event Information</h3>';
// Get the current user ID
$user_id = get_current_user_id();
// Fetch user meta data
$saved_event_venue = $current_user->event_venue;
$saved_hall_stand_number = $current_user->hall_stand_number;
woocommerce_form_field('event_venue', array(
'type' => 'select',
'class' => array('form-row-wide'),
'label' => 'Event/Expo & Venue',
'options' => array(
'' => 'Select an option',
'event1' => 'Event 1 Venue',
'event2' => 'Event 2 Venue',
'event3' => 'Event 3 Venue'
// Add more options as needed
),
'required' …Run Code Online (Sandbox Code Playgroud) custom-fields ×10
wordpress ×8
php ×6
woocommerce ×5
checkout ×2
coupon ×1
group-by ×1
javascript ×1
jira ×1
jira-plugin ×1
jquery ×1
orders ×1
post-meta ×1
python ×1
python-jira ×1
search ×1
velocity ×1