How can I include shortcodes within PHP?

In your case do_shortcode should do the trick. If your shortcode is just like [my_shortcode] then try echo do_shortcode( ‘[my_shortcode]’ ); If you have opening and closing then echo do_shortcode( ‘[my_shortcode]Inner text[/my_shortcode]’ );

How to list commenters and days since last commented

It looks like you could add the MAX( comment_date ) last_commented_date to the field list to get the latest date, each user commented. Then use e.g. the human_time_diff() function to get a human readable text for how long ago each user commented. human_time_diff( strtotime( $result->last_commented_date) ) For safety reasons, you should then prepare the SQL … Read more

add onchange to select in a wp form

you can add any attribute to <select> using wordpress filter wp_dropdown_cats . wp_dropdown_cats filter allows you to modify the content of the taxonomy drop-down output. Try below code. function addAttributeToDropdown($html_content){ $html_content = str_replace(‘<select’,'<select onchange=”myFunc()”‘,$html_content); return $html_content; } add_filter(‘wp_dropdown_cats’,’addAttributeToDropdown’); add this inside your functions.php file

How does WordPress interpret the php code?

functions.php file of a theme gets includeed by WP as any PHP file, there is no special processing or anything. So the code in the file just runs and what happens happens. It is considered proper practice in WP that any code that doesn’t need to run immediately on boot should be instead hooked to … Read more

How to create an ACF shortcode with Repeater Field in WordPress? [duplicate]

you need to return your code when using shortcodes. Additionally you didn’t close the function. try this: function menu_loop() { $menu = ‘<div class=”entry-content dishes”>’; // check if the repeater field has rows of data if (have_rows(‘menu_sections’)): // loop through the rows of data while (have_rows(‘menu_sections’)) : the_row(); // display a sub field value $menu … Read more

Why does this update_post_meta function not delete the custom field itself?

You’re looking for delete_post_meta($post_id, $meta_key, $meta_value); Parameters $post_id (integer) (required) The ID of the post from which you will delete a field. Default: None $meta_key (string) (required) The key of the field you will delete. Default: None $meta_value (mixed) (optional) The value of the field you will delete. This is used to differentiate between several … Read more