How can I use WP_Query to sort ‘event’ custom post type by date?

Found a ready made solution posted in the codex: https://developer.wordpress.org/reference/hooks/pre_get_posts/ The trick here is the pre_get_posts hook which modifies the query variable ‘after the query variable object is created, but before the actual query is run’ so that if the post type is an event, it sorts in the same way I’d been doing already. … Read more

How to distinguish pages created by woocommerce?

You can use conditional tags or function wc_get_page_id(‘page_name’), where page_name can be: ‘myaccount‘, ‘shop‘, ‘cart‘, ‘checkout‘, etc. For example: Using is_cart() you can check whether the current page is a cart page. Using wc_get_page_id( ‘cart’ ); you will receive ID of cart page. Which way is more suitable for your code you have to decide … Read more

Count singular post views automatically

You could hook into template_redirect and execute a helper function: add_action( ‘template_redirect’, ‘wpse_75558_count’ ); function wpse_75558_count() { if ( is_singular() ) setPostViews( get_the_ID() ); } To display the post views, you have to use a later hook. I would recommend the_content: add_filter( ‘the_content’, ‘wpse_75558_show_count’ ); function wpse_75558_show_count( $content ) { $count = getPostViews( get_the_ID() ); … Read more