我正在用drupal构建我的第一个站点.我创建了一个自定义用户字段:全名.现在我想在我的模板中获取此fild的值,说"Hello,%username%".我怎么做?
背景
我使用Advanced Custom Fields Pro管理我的自定义字段,它们有一个"repeater"字段,其中包含存储的子字段,repeatername_X_fieldname其中X是转发器的行号.
我有一个自定义的帖子类型student,attendance其中包含date和包含的转发器class.
因此,当学生上课时,它将按如下方式存储他们的出勤率
为了搜索任何已经去过某个班级或在某个日期范围内就读的学生,我必须挂钩get_meta_sql并将我转换meta_query为使用LIKE而不是=当值包含时%
function key_rewrite($parts){
foreach($parts as &$part){
$part = preg_replace("/(meta_key = )(\'[^']*[%][^']*\')/", "meta_key LIKE $2", $part);
}
return $parts;
}
add_action( 'get_meta_sql', 'key_rewrite');
Run Code Online (Sandbox Code Playgroud)
这让我可以做类似的事情
$args = array(
'post_type' => 'student',
'meta_query' => array(
array(
'key'=>'attendance_%_class',
'compare'=>'=',
'value'=>'History 101'
)
)
);
$my_query = …Run Code Online (Sandbox Code Playgroud) 我试图从Wordpress后端删除自定义字段部分.我想我找到了一个显示自定义字段的函数.该函数位于wp-admin/edit-page-form.php第181行.
do_meta_boxes('page','normal',$post)
Run Code Online (Sandbox Code Playgroud)
当我删除该功能时,Wordpress也不会显示其他框.
如何从Wordpress后端删除特定的框?
在我的Django模型中,我有两个字段name(常规CharField)和slug一个自定义字段,它根据字段定义中传递的字段名称生成slug,在这种情况下我用name它.
首先,该模型只有该name字段,具有相应的迁移和所有.然后我需要添加slug字段,因此遵循南方惯例,我添加了slug字段unique=False,创建模式迁移,然后创建数据迁移,设置unique=True并为最后一次更改创建另一个迁移.
由于slug的值是在模型保存上生成的,在forwards数据迁移的方法中,我所做的是迭代返回的查询集orm['myapp.MyModel'].objects.all()并save()在每个实例上调用方法.
但是从未产生slug字段的价值.在IPython会话下,我做了同样的事情,但引用模型from myapp.models import MyModel,并且工作.使用一些调试语句,打印type由South的orm dict返回的模型显示真实的类,它似乎不是由南方动态构建的假模型.
slug字段在pre_save方法时创建它的值.如何强制在数据迁移期间调用它?我需要确保值的唯一性,以便在以后的模式迁移中应用索引时,列不包含重复值.
谢谢!
BTW:slug字段类确实定义了south_field_triple所以南方玩得很好.
编辑:请看我的答案.但更像是一个答案,感觉更像是一个黑客.有没有更好/正确的方法来做到这一点?
有没有办法让高级自定义字段(ACF)设置规则 =“ALL”?以便此特定组显示在所有页面类型上?
我已经为我的布道自定义帖子类型创建了一个自定义的单个sermons.php模板文件,并希望在此帖子中包含布道说话者的讲道图像自定义字段.
自定义分类ID:sermon_speaker自定义字段ID:sermon_speaker_image
我已经能够获得分类学术语ID以在页面上显示为数字,使用:
<?php
$terms = wp_get_post_terms($post->ID, "sermon_speaker");
foreach ($terms as $termid) {
echo $termid->term_id;
}
?>
Run Code Online (Sandbox Code Playgroud)
我正在尝试弄清楚如何在我目前拥有的代码中使用此术语ID.$ term_id,以便将术语ID添加到背景图像URL的末尾.
<div class="sermon-speaker-image" style="background-image: url('<?php the_field( 'sermon_speaker_image', 'sermon_speaker_' . $term_id ); ?>');"></div>
Run Code Online (Sandbox Code Playgroud)
更新:以下代码是基于以下答案的工作解决方案:
<?php
global $post;
// load all 'sermon_speaker' terms for the post
$terms = get_the_terms($post->ID, 'sermon_speaker');
// we will use the first term to load ACF data from
if( !empty($terms) )
{
$term = array_pop($terms);
$custom_field = get_field('sermon_speaker_image', $term );
}
?>
<div class="sermon-speaker-image" style="background-image: url('<?php echo $custom_field; ?>');"></div>
Run Code Online (Sandbox Code Playgroud) php wordpress custom-fields custom-taxonomy advanced-custom-fields
我想排除每个具有自定义元字段特定值的帖子。问题是,并不是每个帖子都有这个元字段。
我的代码如下所示(工作循环摘录):
// WP_Query arguments
$args = array (
'post_parent' => $parentid,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => array( 'page' ),
'meta_query' => array(
array(
'key' => 'hide',
'value' => 1,
'compare' => '!='
)
)
);
Run Code Online (Sandbox Code Playgroud)
并非每个帖子都使用“隐藏”字段。有些帖子返回 NULL。所以我认为,循环因此不起作用?!
它是否正确?每个帖子都必须有该键的值吗?
在Woocommerce中,我使用自定义字段来计算产品的价格,基于此线程代码:在Woocommerce 3中将产品自定义字段显示为订单商品.
// Add a custom field before single add to cart
add_action('woocommerce_before_add_to_cart_button', 'custom_product_price_field', 5);
function custom_product_price_field() {
echo '<div class="custom-text text">
<h3>Rental</h3>
<label>Start Date:</label>
<input type="date" name="rental_date" value="" class="rental_date" />
<label>Period Rental:</label>
<select name="custom_price" class="custom_price">
<option value="" selected="selected">choosen period</option>
<option value="2">2 days</option>
<option value="4">4 days</option>
</select>
</div>';
}
// Get custom field value, calculate new item price, save it as custom cart item data
add_filter('woocommerce_add_cart_item_data', 'add_custom_field_data', 20, 3);
function add_custom_field_data($cart_item_data, $product_id, $variation_id) {
if (isset($_POST['rental_date']) && !empty($_POST['rental_date'])) …Run Code Online (Sandbox Code Playgroud) 提前感谢您的时间和帮助!
我正在尝试在Play 2.0.4中构建一个自定义表单字段,该字段使用此处的twitter bootstrap datepicker .
基本上,我正在尝试创建一个自定义字段构造函数,输出:
<div class="input-append date error" id="expires_field" data-date="" data-date-format="mm/dd/yyyy">
<label for="expires_field">Expiration Date</label>
<div class="input">
<input class="span2" size="16" type="text" name="expires" id="expires" value="mm/dd/yyyy">
<span class="add-on"><i class="icon-th"></i></span>
<span class="help-inline"></span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
但是,尽管在互联网上大量浏览 - 我一直无法在Play 2.0中创建自定义表单字段,我仍然可以验证并显示错误.
我认为,大多数情况下,我对应用程序结构中文件的位置感到有些困惑.
任何帮助将不胜感激!
Pixelworlds
我已经在产品页面的常规设置选项卡上的WooCommerce Admin中创建了自定义字段,以便为制造插入一些天.我想在每个产品名称上方的购物车和结帐页面上显示此自定义字段值.
这是我的代码:
// Insert a Custom Admin Field
function woo_add_custom_general_fields() {
echo '<div class="options_group">';
woocommerce_wp_text_input( array(
'id' => 'days_manufacture',
'label' => __( 'Days for Manufacture', 'woocommerce' ),
'placeholder' => '',
'description' => __( 'Insert here', 'woocommerce' ),
'type' => 'number',
'custom_attributes' =>
array(
'step' => 'any',
'min' => '1'
)
) );
echo '</div>';
}
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
// Save field
function woo_add_custom_general_fields_save( $post_id ){
$woocommerce_number_field = $_POST['days_manufacture'];
if( !empty( $woocommerce_number_field ) )
update_post_meta( $post_id, 'days_manufacture', esc_attr( $woocommerce_number_field …Run Code Online (Sandbox Code Playgroud) custom-fields ×10
wordpress ×7
php ×5
woocommerce ×2
django ×1
django-south ×1
drupal ×1
drupal-7 ×1
java ×1
meta-boxes ×1
migration ×1
price ×1
product ×1
scala ×1
unique-key ×1