Display hierarchical structure of Custom post type in UL LI

The advanced solution is a Walker. But simplest sotution is a recursive function, which will work just like Walker. You can use one below: function wpse343409_get_recursive_posts( $type=”page”, $parent_id = 0 ) { // default parent 0 means only top level posts $posts = new WP_Query( array( ‘post_type’ => $type, ‘posts_per_page’ => -1, ‘post_parent’ => $parent_id, … Read more

Checkbox field that add a subscription product and change prices of other products in checkout and cart page

I solved the my issue. this code may help others in future. // Display a custom checkout field add_action( ‘woocommerce_checkout_before_terms_and_conditions’, ‘custom_checkbox_checkout_field’ ); function custom_checkbox_checkout_field() { $value = WC()->session->get(‘add_a_product’); woocommerce_form_field( ‘cb_add_product’, array( ‘type’ => ‘checkbox’, ‘label’ => ‘  ’ . __(‘Please check here to get VIP Membership’), ‘class’ => array(‘form-row-wide’), ), $value == ‘yes’ ? true : … Read more

query posts with selected post ids first

I’m not sure if it’s possible to do this in a single query in WordPress. You could potentially split it into two like below: <ul> <?php global $post; // Get posts by selected post ids $args = array( ‘posts_per_page’ => -1, ‘post__in’ => [12345,12543], ‘orderby’ => ‘post__in’ ); $myposts = get_posts($args); foreach ($myposts as $post) … Read more

Getting info about selected posts using one WP_Query

Change $wpb_all_query->prev_post() to $wpb_all_query->the_post(). Class WP_Query does not have prev_post() method, it has the next_post() method, which takes the next post from the results (set up post member of WP_Query object), but it does not set the global variable. To reach for the data of the current post, you must use $wpb_all_query->post (eg. $wpb_all_query->post->post_name ) … Read more

Order by value of Custom Field using url string

Try use get_query_var instead of $_GET and also increase priority function my_pre_get_posts( $wp_query ) { // do not modify queries in the admin if( is_admin() ) { return $wp_query; } // allow the url to alter the query if( isset(get_query_var( ‘budget’ )) ) { $wp_query->set(‘meta_key’, ‘budget’); $wp_query->set(‘meta_value’, get_query_var( ‘budget’ )); } // return return $wp_query; … Read more

How to get taxonomy image attached to a Post Type WordPress

use this snippet here i get image which have post id 5 <img src=”https://wordpress.stackexchange.com/questions/344213/<?php echo site_url(); ?>/wp-content/uploads/<?php echo get_post_meta(5,”_wp_attached_file’,true); ?>’ height=”100″ width=”100″> check get_ani_taxonomy_fields($ani->term_id, ‘acf_image_field_name’) this function return post id