Filtering a list of objects with ‘OR’ on the same field
the function wp_filter_object_list can only filter one value. for your filter try that : $post_tags = array_filter($post_tags, function ($e) { return in_array($e->slug, [“dog”, “cat”]); });
the function wp_filter_object_list can only filter one value. for your filter try that : $post_tags = array_filter($post_tags, function ($e) { return in_array($e->slug, [“dog”, “cat”]); });
Creating a program should be a balanced on how the efficiency of the code work and how easy for future maintenance. For programming efficiency, both style 1 and style 2 of your code is not make a huge impact much. Because of in nowaday PHP, it converts the code into the bytecode only one time, … Read more
A Note on Priorities Note that if you’re trying to remove a function using remove_action() or remove_filter() and the function has had a priority assigned to it, you must include the priority when removing it, or it won’t work. So if the function in the parent theme looks like this: <?php function parent_function() { // … Read more
Generating the excerpt is quite a jumble of filters, so it’s difficult to see precisely what is happening, but here is my guess: WordPress attaches a default filter (see line 148) to get_the_excerpt, namely wp_trim_excerpt. As you can see from the latter function’s source code, it starts with getting the content if it gets passed … Read more
If you look at the gallery shortcode function the opening div (to match that closer you’re missing) looks like this: $gallery_div = “<div id=’$selector’ class=”gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}”>”; then this filter is run $output = apply_filters( ‘gallery_style’, $gallery_style . $gallery_div ); More than likely there’s code somewhere in your theme or a plugin that’s messing … Read more
The way apply_filters() works is that the developer provides a name for the filter, and the value that can be filtered. This lets other code modify that value by adding a filter. In addition the value, however, apply_filters() can also pass additional values to hooked functions so that they can be used inside the filter … Read more
Is it possible to bind a function to a filter hook via Ajax? No, because page requests are self contained. When you request something from PHP, everything gets loaded from a fresh clean slate. At the end of the request, that slate is discarded. This is different from say a Node application that is always … Read more
First of all if you are already checking if the field is empty with that function, there’s no need to use * in the backoffice [email* your-email]. In any case, it’s not working because is_required()executes first than your function. Solutions: 1) Remove the * in the backend OR 2) Change the priority // From 20 … Read more
The question is: Is it possible to hook with apply_filters or add_filters on their function, manipulate it adding HTML to that page? apply_filters and add_filter() do two separate things. apply_filters allows a value to be filtered by add_filter(). This means that if the original code is 3rd-party, you can only use add_filter() if that code … Read more
There’s a couple ways you could handle this. Option 1 Check the global $post object Inside your filter you may be able to check the current $post object or other Conditional Tags for a specific type. function my_super_filer_function6( $args ) { global $post; /* Check against the current post object */ if( empty( $post ) … Read more