Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1415111
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionI write a plugin. it has the ability to filter post by category and also its subcategories. I get some error and I don't know why I get it! I commented on the errors. Could you help me?
function wf_get_all_category( $taxonomy = 'category', $parent = 0, $hide_empty = true ) {
$result = [];
$terms = get_terms( [
'taxonomy' => $taxonomy,
'hide_empty' => $hide_empty,
'parent' => $parent,
] );
if ( count( $terms ) ) {
foreach ( $terms as $term ) {
$t_id = $term->term_id;
$term_fields = get_option( "taxonomy_$t_id" );
$filter_show = $term_fields['filter_show'];
if ( $filter_show != 1 ) {
$result[] = $term;
}
}
}
return ( $result );
}
function wpf_cats( $cats = [], $taxonomy = 'category' ) {
$count = 0;
$out_html = '';
foreach ( $cats as $cat ) {
if ( isset( $cat->parent ) && !is_numeric( $cat->parent ) ) {
continue;
}
$cat_list = wf_get_all_category( $taxonomy, $cat->parent ); //Trying to get property 'parent' of non-object
if ( count( $cat_list ) ) {
$ajax_class = $cat->parent != 0 ? "wpf-filter-ajax" : ""; //Trying to get property 'parent' of non-object
$out_html .= "<select id=['parent-$cat->parent'] class='wp-filter " . $ajax_class . "'>"; //Trying to get property 'parent' of non-object
$out_html .= " <option data-slug='none' value='none'> Chose a Category</option>";
foreach ( $cat_list as $term ) {
$out_html .= "<option data-slug='"
. get_term_link( $term ) . "' " . selected( $cat->term_id, $term->term_id, false ) //Trying to get property 'term_id' of non-object
. " data-taxonomy='" . $term->taxonomy . "' value='" . $term->term_id . "'>" . $term->name . "</option>";
}
$out_html .= "</select>";
}
}
return $out_html;
}
add_shortcode( 'me-wp-filter', 'me_wp_filter' );
function me_wp_filter( $html ) {
$parent_list = false;
$taxonomy = "category";
if ( is_category() ) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj;
$parent_list = wpf_parent_list( $thisCat );
array_push( $parent_list, $thisCat );
$taxonomy = "category";
}
if ( is_single() ) {
return '';
}
$html .= '<div class="woo-filter-select-warp">
<div class="select-box">
';
$html .= '<span class="wpf-list-box">';
if ( $parent_list ) {
$html .= wpf_cats( $parent_list, $taxonomy );
} else {
$html .= wpf_cats_first( 0, $taxonomy );
}
$key_class = "close";
$key = '';
if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
$key_class = "open";
$key = $_GET['s'];
}
$html .= '</span>
<span class="wp-filter-mode_input">
<div class="' . $key_class . ' form">
<input type="text" id="key" placeholder="کلمه کلیدی" value="' . $key . '"/>
<div class="after"></div>
</div>
<button type="button" id="go-filter" class="material-button ripple widget_submit has-ripple mbtn">فیلترکن!</button></div>
</span>
</div>';
return ( $html );
}
本文标签: debugProblem In Advance search Plugin
版权声明:本文标题:debug - Problem In Advance search Plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745205360a2647613.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论