New template file does not load category-specific post
New template file does not load category-specific post
New template file does not load category-specific post
Use the save_post hook to check if a post that is being saved is a portfolio page and reset the transient. add_action( ‘save_post’, ‘reset_portfolio_transient’, 10,3 ); function reset_portfolio_transient( $post_id, $post, $update ) { // Only set for portfolio post_type if ( ‘portfolio’ !== get_post_type($post) ) { return; } // delete old tranisent delete_transient( ‘randomizeProfiles’ ); … Read more
Update: The User has clarified the request in the comment to my answer, so i add some info above my original answer. The original answer is still valid 😉 To use external data for your “main” query, you can use the pre_get_posts hook. Use it like this: add_action(‘pre_get_posts’,’get_radius_instructors_for_my_posts’); function get_radius_instructors_for_my_posts($query){ if($query->is_main_query() && !is_admin()){ if($query->is_search()){ //use … Read more
the_permalink() echoes the output, and so does the_title() by default. So you should use get_permalink() and get_the_title(): $html .= ‘<h3><a href=”‘ . get_permalink() . ‘”>’ . get_the_title() . ‘</a></h3>’; Or use the_title() with the third parameter set to false to return and not echo the output: $html .= ‘<h3><a href=”‘ . get_permalink() . ‘”>’ . … Read more
Products variations are a stored as a different post type, product_variation, so you have to add that post type to the query: ‘post_type’ => array( ‘product’, ‘product_variation’ ) Also, you could try to use WooCommerce specific functions, like wc_get_product_ids_on_sale(), wc_get_products() and so on, they could make your life easier when coding for WooCommerce.
Because I don’t have the exact settings, I just make use of the variables showing in the questions to code. The code is tested with similar settings with meta value. If using WP_Query object, one more custom field is required to achieve the effect $queryArgs = [ ‘post_type’ => ‘author_cpt’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => … Read more
WP_Query random ordering not working since 5.4
If you don’t want a query to run on the admin you can call the conditional function is_admin() to check, if it returns true you can just return out of the function. Additionally, pre_get_posts is an action hook. function exclude_product_cat_children( $wp_query ) { if( is_admin() ) { return; } if( isset( $wp_query->query_vars[‘product_cat’] ) && $wp_query->is_main_query() … Read more
WordPress has quite a few global variables to choose from which may help. For example, you can use the global $post to get first post in the query. global $post; $my_meta_value = get_post_meta( $post->ID, ‘_another_meta_key’, true ); Or you could reach directly into the $wp_query object posts array and grab the first post: global $wp_query; … Read more
The meta field Addon have the meta value 129456,968945,495435 as string. To use this value in a meta query, you should split the value into an array. Like array( 129456, 968945, 495435 ). WordPress have a very good function wp_parse_id_list(), which can split comma separated items into array. <?php if ( ! empty( $addons = … Read more