How to display Custom Post Type Post based on Tag with Shortcode Parameter?

This is an answer that depending on how you ultimately configure things – should get you where you want to go. In your question, you had posts_per_page as 1. If you only want 1 result, then that’s fine. If not… modify as shown. You also didn’t initialize the concatenated string $return_string and finally you put … Read more

WooCommerce get_price returning wrong price when used via ajax

It’s important to exit the function when using the wp_ajax hooks. Hopefully this fixes it. function get_ticket_price() { $ticketID = $_REQUEST[‘ticketID’]; echo wc_get_product( $ticketID )->get_price(); // Don’t forget to stop execution afterward. wp_die(); } add_action( ‘wp_ajax_get_ticket_price’, ‘get_ticket_price’ ); add_action( ‘wp_ajax_nopriv_get_ticket_price’, ‘get_ticket_price’ );

Register JS for block on frontend only

If you’re using WordPress 5.8 (e.g. v5.8.3), then I’m afraid the answer to this: I know that I can use is_admin() to check if it’s in the editor and not load a js file but I’m trying to see how it can be done with register_block_type(). .. is it can’t; not in WordPress 5.8. More … Read more

Why is variable not working on custom sql query using wpdb?

Huge thanks to @kero !! I was finally able to create a solution by making the sql statement a variable first (as kero suggested) then using that variable on wpdb->query(); Here’s my updated and fully working codes now: $imdbid = $_GET[‘id’]; $string = file_get_contents(“http://www.omdbapi.com/?i=”.$imdbid.”&apikey=9a187152″); $json = json_decode($string, true); if( $json[‘Response’] === “True” ){ $dataID = … Read more

Automatically add custom CSS to new posts using a category template

If you have created a custom php template then add a specific class selector to your css within this template. As an example: <body class=”mycustomclass”>all your page content</body> or <content class=”mycustomclass”>all your content content</content> It doesn’t have to be on body or content or any other specific part of the page but make it encompass … Read more

An extra ‘ is displayed in the title

Those look like smart apostrophes to me. They have a curve on theme. Try: <title><?php wp_title(‘ | ‘, ‘echo’, ‘right’); ?> – <?php bloginfo(‘name’); ?></title> Otherwise post what you have around that php section too.

Adding hreflang tags automatically in WordPress subdirectory multisite

Alternatively we can set the hreflang as a site meta for each site: update_site_meta( 1, ‘hreflang’, ‘x-default’ ); update_site_meta( 3, ‘hreflang’, ‘en-au’ ); update_site_meta( 5, ‘hreflang’, ‘en-gb’ ); and then for the hreflang attribute use; get_site_meta( $site->blog_id, ‘hreflang’ ) and for the href attribute: get_home_url( $site->blog_id, $page_path ) If we want to skip the site … Read more