Remove query string specific key value

[EDIT] This should work the way you wanted it to: $marca = get_query_var(‘marca’); $marca_arg = isset($marca) && is_array($marca) ? $marca : []; $url_base = remove_query_arg( ‘marca’ ); $n = count( $marca_arg ); foreach ($marcas_terms as $marca_term) { $selected = in_array( $marca_term->slug, $marca_arg ); if ( $selected ) { $marca_arg2 = array_diff( $marca_arg, [ $marca_term->slug ] … Read more

How to restrict page access to logged-in users?

How about this? function my_force_login() { global $post; if (!is_single()) return; $restricted_parent_id = 1 // Whatever id you are targeting. if ($post->post_parent == $restricted_parent_id && !is_user_logged_in()) { auth_redirect(); } } More info on post_parent and other conditional tags here: https://codex.wordpress.org/Conditional_Tags

A good strategy to print custom posts (offer) that are checked inside the metabox of a post?

The feature is achieved in this way! function op_register_menu_meta_box() { add_meta_box( ‘op-menu-meta-box-id’, // Metabox ID esc_html__( ‘Custom offers Checklist (select any 2)’, ‘text-domain’ ), //Metabox Title ‘op_render_menu_meta_box’, // Metabox Callback Function ‘listing’ // Place Where this Metbax Should Appear ); } add_action( ‘add_meta_boxes_listing’, ‘op_register_menu_meta_box’ ); //Metabox Hook The callback function! function op_render_menu_meta_box( $post ) { … Read more

Change Admin Bar “Visit Site” URL

The admin bar is using the home_url() function which you can modify the result by using the “home_url” filter, this will change a lot of links on your admin area so looks like it’s not the best solution, anyway remember to use the is_admin() conditional tag or you will affect everything on the front end … Read more

Convert all images to PNG on file upload

(Updated answer) The sight() function not only uploads the image, but also creates an attachment (i.e. a post of the attachment type); hence, I updated the code — it’s now in a function named attachment_to_png, and that it uses the get_attached_file() to get the image file attached to that attachment, and the update_attached_file() to update … Read more

How to remove howdy dropdown menu content

You can use wordpress nodes to customize profile menu. Add this in functions.php add_action( ‘admin_bar_menu’, ‘remove_my_account’, 999 ); function remove_my_account( $wp_admin_bar ) { $wp_admin_bar->remove_node( ‘my-account’ ); } add_action( ‘admin_bar_menu’, ‘add_logout’, 999 ); function add_logout( $wp_admin_bar ) { $args = array( ‘id’ => ‘logout’, // id of the existing child node (New > Post) ‘title’ => … Read more

Load JS Script only for custom post types

To enqueue scripts on the front-end, the hook should be wp_enqueue_scripts, not login_enqueue_scripts. Also, a better way to see if you’re on a single custom post type is to use is_singular() and pass the post type you want to check: if ( is_singular( ‘events’ ) ) { } get_post_type() relies on the global $post object, … Read more

Use wp_get_recent_posts with search term

It should just be a matter of setting the ‘s’ argument of wp_get_recent_posts() (or just get_posts()) to the search term: $args = array( ‘numberposts’ => $numberposts, ‘offset’ => $offset, ‘category__not_in’ => array(391), ‘category’ => $category, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘s’ => $searchterm, ); $recent_posts = wp_get_recent_posts( $args, … Read more