我正在尝试添加一个AJAX实时搜索来过滤我的wordpress主题中的帖子标题,以对输出帖子列表进行排序。我已经添加了当前输出的图像。请
我添加了一个输入字段,用于过滤列表视图
<input placeholder="Search here........." type="text" />
Bellow是我的自定义页面类型,用于输出自定义帖子列表,我的自定义帖子类型为circular
<?php /*Template Name: Circular search*/
function TrimTitle($s) {
$maxLength = 80;
if (strlen($s) > $maxLength) {
echo substr($s, 0, $maxLength - 5) . ' ...';
} else {
echo $s;
}
}
?>
<?php get_header(); ?>
<input placeholder="Search here........." type="text" />
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$circular_query= new WP_Query(array(
'post_type'=>'circular',
'posts_per_page' => 7,
'order' => 'DESC',
'paged' => $paged,
));
if($circular_query->have_posts()) :
while($circular_query->have_posts()) : $circular_query->the_post();
$file = get_post_meta(get_the_ID(), 'circular_attachment', true);
//get the url
$url = $file['url'];
?>
<ul>
<li>
<a href="<?php the_permalink() ?>" title="Link to <?php the_title_attribute() ?>">
<i class="fa fa-file-pdf-o circular-list-icon" aria-hidden="true"></i> <?php the_time( 'd-m-Y' ) ?> <?php TrimTitle(get_the_title()); ?>
</a>
<a class="download-btn read-more btn btn-primary" href="<?php echo $file['url']; ?>"> Download</a>
</li>
<hr class="sep-circular"/>
</ul>
<?php endwhile;
$total_pages = $circular_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('« prev'),
'next_text' => __('next »'),
));
}
?>
<?php else :?>
<h3><?php _e('No Circular found', ''); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>
<div class="sep-circular clearfix"></div>
<?php get_footer(); ?>
答案 0 :(得分:0)
在您的查询中,您没有告诉WordPress要订购哪个字段。试试这个:
##
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\DMECHCH\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:/Users/DMECHCH/OneDrive/Courses ARA/Diploma IT Tech Support Courses/DTEC501 - Programming fundementals/Week 14 Session 1/14-3 Q1.py", line 119, in <lambda>
check_btn = Button(root_window,text="Change Password",command=lambda: validate_password(pwd1, pwd2))
File "C:/Users/DMECHCH/OneDrive/Courses ARA/Diploma IT Tech Support Courses/DTEC501 - Programming fundementals/Week 14 Session 1/14-3 Q1.py", line 27, in validate_password
pwd_length = len(password)
TypeError: object of type 'StringVar' has no len()
##
另外,我将结果顺序设置为ASC而不是DESC,因为我认为您希望以ASC顺序发布帖子,不是吗?