post_orderby filter breaks function
-
I have a custom shortcode function to display a list of articles. The list needs independent styling based on the post tag. That part all works. I need it to be sorted by term_order. I created a post_orderby filter to override the query, but when I apply it, it breaks the link to the page. Any help on why this might be happening is appreciated.
//add filter to change the order by of the query done by WP_QUERY: function my_query_orderby($orderby) { global $wpdb; return "{$wpdb->term_relationships}.term_order ASC"; } add_filter('posts_orderby', 'my_query_orderby'); function create_article_list($attr) { // Initialize variable and check for shortcode content $return = ''; if( $content ) { $return = $content; } $args = shortcode_atts( array( 'term' => '68', ), $attr ); $terms = array($args['term']); $query = new WP_Query( array( 'post_status' => 'publish', 'numberposts' => -1, 'post_type' => 'user_guide', 'orderby' => 'term_order', 'order' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'user_guide_categories', 'terms' => $terms, 'field' => 'term_id', 'operator' => 'IN', 'include_children' => true ) ), ) ); while ( $query->have_posts() ) { $first = ''; $tags = array(); $tags = get_the_tags(); $tag = $tags[0]->name; if ($tag == "essential") { $return .= $first . '<a id=article-list-user-guide href="' . get_permalink() . '">' . '<i class="fa-solid fa-star-of-life"></i>' . get_the_title() . '</a><br>'; $first = '<br>'; } elseif ($tag == "admin") { $return .= $first . '<a id=article-list-admin-guide href="' . get_permalink() . '">' . get_the_title() . '</a><br>'; $first = '<br>'; } } return $return; } add_shortcode('my_shortcode', 'create_article_list');
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘post_orderby filter breaks function’ is closed to new replies.