How to create a php variable using WordPress the_title() function

Indeed, the the_title function echoes the title, unless you set the third parameter to false (default true). So you start with this; $title = the_title (”,”,false); Now, $title may contain all kinds of characters that cannot be used in PHP variable names, so we need some sanitization: $title = preg_replace(‘/[^A-Za-z0-9\_]/’, ”, $title); // Removes special … Read more

Woocommerce : Can’t get product info in loop

First of all, get_price_html() outputs html code for product price. To get sale price specifically, use get_sale_price() instead, and get_price() to get regular price. Use Chrome web dev tool to inspect for any php error. The Loop breaks after outputing title, so my guess would be to look for error there.

Creating own shortcode – echoeing php variable based on JS variable

You can’t add logic for changing in that way. You need react on user “front-end” event with js. Also this construction will work wrong: document.getElementById(\”form\”).innerHTML = \”[contact-form-7 id=\”formId\”]\”; Will be always print [contact-form-7 id=\”formId\”], because js can’t do_shortcode function itself. If you wanna make it simple(without ajax process) you need: 1) Print all forms with … Read more

Displaying Hierarchical custom taxonomy

If you want to sort your terms by hierarchy, you can use wp_get_post_terms() instead. It’s usage is similar to get_the_term_list(). Take a look at this simple example: wp_get_post_terms( $post->ID, $taxonomy->name, array( ‘orderby’ => ‘term_id’ ) ); I think we can safely assume that the parent will mostly have a lower ID of its childs (if … Read more