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

Filtering a function’ output for a new continued function

How about using a standard for loop instead: $sunnytags = get_tags ($tagargs); $count = count ($sunnytags); for ($i = 0; $i < ($count < 15 ? $count : 15); $i++) { $string .= ‘<a class=”tag2″ href=”‘. get_tag_link ($sunnytags[$i]->term_id) .'”>’. $sunnytags[$i]->name . ‘</a>’; } And then later, whether you re-run the query or (better still) save … Read more

Conditional statement for dates

instead of $currentdate = current_time(‘Ymd’); you can use $currentdate = new DateTime(); so the Final Solution should be as like given below <?php $currentdate = new DateTime(); $date = get_field(‘course_start_date’, false, false); $date = new DateTime($date); if ($currentdate > $date) { echo ‘ – Started.’; } else { echo ‘ – Not started.’; } ?>

php within html within php

You can format it as, there’s also no need to put the echo <?php next_post_link(‘%link’,”<img src=”https://wordpress.stackexchange.com/questions/251458/. CFS()->get(“image_location’) . “/>”); ?> CFS()->get(‘image_location’) gets the field based on the current post id. If you want to use it for the next or previous, you have to pass the next or previous posts ID. You can do something … Read more

src script only works on home page?

First, don’t put script tags directly in template files, enqueue them from your theme/child theme’s functions.php. Second, use the API to output URIs for scripts, don’t hardcode or use relative paths. function wpdocs_theme_name_scripts() { wp_enqueue_script( ‘flexslider’, get_template_directory_uri() . ‘/js/jquery.flexslider.js’, array(‘jquery’), null, true ); wp_enqueue_script( ‘fancyselect’, get_template_directory_uri() . ‘/js/fancySelect.js’, array(‘jquery’), null, true ); wp_enqueue_script( ‘myscript’, get_template_directory_uri() … Read more

Is there any way to get a drop down list of time zones?

Enter wp_timezone_choice(): <select> <?php echo wp_timezone_choice( ‘UTC’ ) ?> </select> Make sure to check out the documentation link, but the parameters are: $selected_zone (string) (Required) Selected timezone. $locale (string) (Optional) Locale to load the timezones in. Default current site locale.