wp_redirect() not working in Insert PHP plugin in WordPress

I have used WordPress’ custom POST handler functionality before to solve a problem similar to the issue that you are having. Here is documentation from the codex on this: https://codex.wordpress.org/Plugin_API/Action_Reference/admin_post_(action) Basically, you would use an action to handle the post request: function my_handle_form_submit() { // This is where you will control your form after it … Read more

Different output from WP-CLI in bash vs PHP exec()

According to Alain Schlesser in wordpress slack: The folder that the packages are installed into is set to use your server user’s home folder. When you try to execute this command from PHP, however, it is being executed by the webserver’s user, which probably has a different home folder, and the package is not installed … Read more

Remove duplicates – array_unique()

I was able to answer my question thanks to : https://wpquestions.com/Remove_duplicates_from_ACF_query/12685 <?php $posts = get_posts(array( ‘numberposts’ => -1, ‘post_type’ => ‘page’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, )); if($posts) { /* FIRST, get all the post data */ foreach($posts as $post) { /* SECOND, one-by-one, add each data row for the specific field into an … Read more

Only show search results with if current date is between two dates?

You can use meta queries to filter posts according to your needs. Here is a sample code: function SearchFilter( $query ) { if ( !is_admin() && $query->is_search ) { $query->set( ‘post_type’, ‘visitor’ ); $query->set( ‘meta_query’, array( ‘relation’ => ‘AND’, array( ‘key’ => ‘visitor-start-date’, ‘value’ => time(), ‘compare’ => ‘<=’ ), array( ‘key’ => ‘visitor-date’, ‘value’ … Read more

WordPress custom slug (endpoint) and compare all links

All of the API functions that generate links have filters to let you alter the output. Here’s a quick example that covers most of them: function wpd_endpoint_links( $url ){ if( isset( $_COOKIE[‘lang’] ) ){ $url = $url . $_COOKIE[‘lang’] . “https://wordpress.stackexchange.com/”; } return $url; } add_filter( ‘post_link’, ‘wpd_endpoint_links’ ); add_filter( ‘page_link’, ‘wpd_endpoint_links’ ); add_filter( ‘post_type_link’, … Read more

Count top level menu items

I am not really sure whether there is some native function for this or not, but you could do it like this: $menu_object = wp_get_nav_menu_object(“Main menu”); $menu_items = wp_get_nav_menu_items($menu_object->term_id); $menu_items_count = 0; foreach ( (array) $menu_items as $key => $menu_item ) { if ($menu_item->menu_item_parent == 0 ) $menu_items_count++; }

Setting a cookie upon specific URL visit

I’ve used this and it works: add_action(‘init’, ‘optin_cookie’, 1); function optin_cookie(){ $currentURL = “https://” . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’]; if ( $currentURL == ‘https://25dni.si/delovanje-uma/’ ) : setcookie( ‘opt_in’, has_opt_in, time()+31556926, “https://wordpress.stackexchange.com/”); elseif ( $currentURL != ‘https://25dni.si/’ ) : if ( ! isset( $_COOKIE[‘opt_in’] ) ) : endif; endif; } I’m sure there is a much more … Read more

How do I get current page ID in WordPress customizer file?

Thanks for your question. active_callback is exactly what you’re looking for. You can use it with controls: $wp_customizer->add_control( ‘setting_name’, array( ‘type’ => ‘text’, ‘section’ => ‘section_name’, ‘label’ => ‘Option with context’, ‘active_callback’ => ‘is_front_page’ ) ); and with sections: $wp_customize->add_section( ‘section-name’, array( ‘title’ => ‘Section with context’, ‘active_callback’ => ‘is_front_page’ ) ); In examples above, … Read more