1
我想验证并更改来自wordpress搜索表单的输入值。使用php验证/更改输入值
<?php $unique_id = esc_attr(uniqid('search-form-')); ?>
<form role="search" method="get" class="search-form" action="<?php echo esc_url(home_url('/')); ?>">
<label for="<?php echo $unique_id; ?>">
<span class="screen-reader-text"><?php echo _x('Search for:', 'label', 'twentyseventeen'); ?></span>
</label>
<input type="search" id="<?php echo $unique_id; ?>" class="search-field" placeholder="<?php echo esc_attr_x('Search …', 'placeholder', 'twentyseventeen'); ?>" value="<?php echo get_search_query(); ?>" name="s" />
<button type="submit" class="search-submit">
<?php echo twentyseventeen_get_svg(array('icon' => 'search')); ?><span class="screen-reader-text"><?php echo _x('Search', 'submit button', 'twentyseventeen'); ?></span></button>
</form>
我用这个代码来更改值,但它不是工作;-(
这应该删除所有字符和测试之后,但它不是。
我这么想吗?
最后,我想验证输入值,当它包含特定的单词时,它需要更改为干净的搜索字符串。
我想这:'$查询= SUBSTR ($ query,0,strpos($ query,“&catalogRefIds =”));'但我得到一个错误'解析错误:语法错误,意外'$查询'(T_VARIABLE),期望函数(T_FUNCTION)在/ home/voordnl /public_html/wp-includes/class-wp-query.php on line 467' – Maarten
@Maarten查询是对象的外观: https://codex.wordpress.org/Class_Reference/WP_Query –