Count custom posts type and filter by tag

wp_count_posts is not affect your custom query. You can use found_posts to return the number of posts from the custom query. So try to change the code after your loop query as follows. Hope it helps. if ($loop->have_posts()) : $count_posts = $loop->found_posts; echo “<p>Total: $count_posts cars</p>”; else : echo “<p>No cars available.</p>”; endif; wp_reset_query();

I have an error WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version

The problem here you are passing table name as a placeholder in prepare statement. Which is not allowed. You can directly add the table name in your query without quotes. Your query do not have any placeholder and arguments. So No need for prepare statement. Try following code. global $wpdb; $vragen = $wpdb->get_results( “SELECT * … Read more

How call WordPress shortcode inside function file

I need echo do_shortcode(‘[Shortcode]’); to go where it says “New Item Contents here!” is there any way to do this? Just put it there: add_action( ‘woocommerce_account_new-item_endpoint’, ‘add_new_item_content’ ); /** * Add content to the new tab. * * @return string. */ function add_new_item_content() { echo do_shortcode(‘[Shortcode]’); } Maybe I’m misunderstanding the question, but that’s all … Read more

get_query_vars always retruns empty value

In my test scenario I use the original twentytwentyone theme with no plugins activated. My code is placed at the end of functions.php. This is the problem. Your code is running as soon as functions.php is loaded, which is before the query vars are populated. If you use get_query_var() inside an action hook that runs … Read more

add_post_type_support but for front_page only

If you want to enable excerpt for specific page, then you can add some conditions to narrow down. For check “front page id” you can use get_option(‘page_on_front’); in admin area. (is_front_page() should not work here) global $pagenow; // check current screen is edit page if ( $pagenow == ‘post.php’ ) { $fron_page_id = get_option(‘page_on_front’); $current_page … Read more

Sorting a custom post type in pre_get_posts

You can add a filter on posts_clauses to; left join additional columns for each meta filter add order by clause base on those column values. Something like below should work, assuming your meta key is start_date and the value has the actual date format Y-m-d and your post type is talks add_filter( ‘posts_clauses’, function ($clauses, … Read more

ajax problems on loading page [closed]

I finally find out the problem. The problem is when I load wordpress page a builtin ajax call is started. and this part of my code: jQuery(document).ajaxStart(function() { jQuery( “#step-general” ).hide(); jQuery( “.pelak-loader” ).show(); }).ajaxSuccess(function() { jQuery( “.pelak-loader” ).hide(); }); is used on loading page. I use if conditional in ajaxStart to limit its border!