add another variable to php function

Well I figured out I could duplicate the function and rename the title so it runs twice. But for future, is there a more elegant way of doing this in one instance? thanks! // orderby slideshows function modify_slider_order($query, $slider_id) { // only alter the order for slider with “x” ID // https://tinyurl.com/zb6hzpc if($slider_id == 17 … Read more

Is it possible to update the dataset using update_post_meta

You don’t need your second foreach loop. foreach( $_POST[‘wt_set’] as $name => $val ){ update_post_meta( $post_id, $name, $val ); } What’s happening is with your second foreach is each entry is being processed individually and set as the post meta, so as it’s looping through it’s running update_post_meta( $post_id, $name, XXX ); then update_post_meta( $post_id, … Read more

is_front_page is not working in my functions.php

add_action(‘init’, ‘save_landing_page_slider’, 10, 2); init is too early — if you look at the WordPress query overview on Codex, init is (as of writing) the second step, whereas is_ variables like $is_page (or WP_Query::$is_page) that are used by conditional tags like is_front_page() are only set in step 4, so instead of init, you should use … Read more

excep tonly one css, don’t load any css

If this code works as excpected and you want to only limit it to front page you need to add a check for front page, like this function pm_remove_all_styles() { if (!is_front_page()) return; // add this global $wp_styles; $wp_styles->queue = array(); wp_register_script(‘hekimscripts_input’, get_template_directory_uri() . ‘/js/stylespure.css’, array(), ‘2.7.1’); // input css wp_enqueue_script(‘hekimscripts_input’); // Enqueue it! } … Read more

Display articles with a different template in the home page | Solved |

I haven’t tested this, but it looks like you just need to set an iteration variable (usually abbreviated $i), like this: <?php $i = 0; // This sets your variable $query = [ ‘post_type’ => ‘post’, ‘posts_per_page’ => 5 ]; $query = new WP_Query($query); while ($query->have_posts()) : { $query->the_post(); if($i == 0) : get_template_part(‘loops/acc-cards’); else() … Read more

How to get latest post ID in functions.php?

Here is the code that should probably work for you: function bt_update_user_homepage_meta() { // Get user id $user_id = get_current_user_id(); if ( !empty( $user_id ) && is_page( [ ‘home’ ] ) ) { $posts = wp_get_recent_posts( array( ‘numberposts’ => 1, ‘meta_key’ => ‘usp-custom-1’, ‘meta_value’ => ‘question’ ) ); if ( !empty( $posts ) ) { … Read more