How to make query loop block dynamic
How to make query loop block dynamic
How to make query loop block dynamic
You can filter the posts list by appending ?category_name=xx to the admin posts list URL, and you can add a submenu page with that URL as the target via add_submenu_page: add_action( ‘admin_menu’, ‘wpd_admin_menu_item’ ); function wpd_admin_menu_item(){ add_submenu_page( ‘edit.php’, ‘Page title’, ‘Menu item title’, ‘edit_posts’, ‘edit.php?category_name=somecat’ ); }
Update Solution was easy I’m stupid I just tweaked the menu creation and directly assigned the parent-menu-id: if (!empty($term->parent) && $term->parent != 0) { $parent_menu_item_id = get_parent_menu_item_id_by_name($term->parent, $menu_id); if ($parent_menu_item_id) { $menu_item_id = wp_update_nav_menu_item($menu_id, 0, array( ‘menu-item-title’ => $term_name, ‘menu-item-object-id’ => intval($term_id), ‘menu-item-object’ => ‘product_cat’, ‘menu-item-type’ => ‘taxonomy’, ‘url’ => get_term_link($term), ‘menu-item-parent-id’ => $parent_menu_item_id, ‘menu-item-status’ … Read more
The argument isn’t category, it is cat. Your query fails because you are using an argument that doesn’t exist. $args = array( ‘post_type’ => ‘post’ , ‘orderby’ => ‘date’ , ‘order’ => ‘DESC’ , ‘posts_per_page’ => 6, ‘cat’ => ‘3’, ‘paged’ => get_query_var(‘paged’), ‘post_parent’ => $parent ); $q = new WP_Query($args); if ( $q->have_posts() ) … Read more
The question has already been asked and the answer has been posted too, How to display related posts from same category? Add this code inside your single.php after a loop wherever you want to show related post, <?php $related = get_posts( array( ‘category__in’ => wp_get_post_categories($post->ID), ‘numberposts’ => 5, ‘post__not_in’ => array($post->ID) ) ); if( $related … Read more
One possibility: $related = get_posts( array( ‘category__in’ => wp_get_post_categories( $post->ID ), ‘numberposts’ => 5, ‘post__not_in’ => array( $post->ID ) ) ); if( $related ) { foreach( $related as $post ) { setup_postdata($post); /*whatever you want to output*/ } wp_reset_postdata(); } Reference: get_posts wp_reset_postdata wp_get_post_categories Answer re-written based on WP_Query(): $related = new WP_Query( array( ‘category__in’ … Read more
In the function wp_get_post_terms() you can select the taxonomy. the default is post_tag you can change it to category. And in the WP_Query args you need to change the tag__in to category__in. // get the categories $categories = wp_get_post_terms($post->ID, ‘category’); if ($categories) { $categories_ids = array(); foreach($categories as $individual_cat) $categories_ids[] = $individual_cat->term_id; $args=array( ‘category__in’ => … Read more
To directly answer your question, you can use the wp_setup_nav_menu_item filter to change properties of the nav menu item: add_filter( ‘wp_setup_nav_menu_item’, static function ( $menu_item ) { if ( ! is_admin() || empty( $menu_item->taxonomy ) || ‘category’ !== $menu_item->taxonomy ) { return $menu_item; } $menu_item->title .= sprintf( ‘ (%s)’, $menu_item->slug ); return $menu_item; } ); … Read more
As you may have noticed get_the_author() returns the author of the current post. You’lle need to use WP_User_Query to get the authors. E.g. $author_query = new WP_User_Query( [‘role’ => ‘Author’] ); By default the query returns an array of WP_User objects.
Instead of hard-coding the pages, categories and sidebars in your template file(s) you could consider registering a custom metabox to store the category relation (i.e. the category term ID) in the page post meta. This way you could make the sidebar handling dynamic. The first step would be to register, render and handle the saving … Read more