New answers tagged

-4

I know the answer is late but there is great article written by one blogger.


1

This question has been answered on Stack Overflow before: http://stackoverflow.com/a/14626254/844732 add_action( 'admin_head', 'check_page_template' ); function check_page_template() { global $post; if ( 'page-homepage.php' == get_post_meta( $post->ID, '_wp_page_template', true ) ) { // The current page has the foobar template assigned ...


0

Here you go.. add_action( 'gform_after_update_entry_7', 'add_length_on_update', 10, 2 ); function add_length_on_update( $form, $entry_id ) { if( !empty($_POST["input_3"]) && !empty($_POST["input_27"]) && !empty($_POST["input_28"]) ){ // get input from form $date = $_POST["input_3"]; $start = ...


0

Hook the woocommerce_currency filter. function change_woocommerce_currency( $currency ) { if ( is_product_category( 'my-special-cat' ) ) { $currency = 'myCred' // or whatever the currency symbol is } return $currency; } add_filter( 'woocommerce_currency', 'change_woocommerce_currency' );


1

to see list of functions or actions hooked to a particular action hook you can use the following code. global $wp_filter; echo '<pre>'; var_dump( $wp_filter['wp_head'] ); echo '</pre>';


0

Ok after trying a bunch of different plugins, scripts, and custom coding, I've come across one that seems to be perfect! Only thing now is to figure out how to implement it in my site. My Solution


2

Filters are for modifying data that's passed through them. You need to take the input, modify it, then return it. function exclude_not_allowed_terms( $args, $taxonomies ) { if(!current_user_can('edit_others_posts') && in_array( 'my-taxonomy', $taxonomies ) ) { $args['meta_query'] = array( array( 'key' ...


0

It isn't happening to me (I just checked with your example), so it must be something that's occurring in the theme or a plugin. You could try searching all of the codebase for the wp_title filter, but you might get a lot of results to sort through. An easier option might be switching the theme to the default, or disabling plugins and then re-enabling them ...


0

I hope I understood you correctly as your question is a bit scrambled BACKGROUND Functions, just like your car, are pretty useless objects until they are put to use of some kind. Simply being defined in functions.php or in a plugin makes functions as useful as a car parked in a garage, it is there, but doing nothing useful at that given point in time. ...


1

Here is an example of what I've done: <?php $link = home_url( '/members/' . bp_core_get_username( bp_displayed_user_id() ) . '/followers/' ); echo "<a href='". esc_attr( $link ) ."'>Followers</a>"; ?> So maybe its home_url now, than site_url. In the echo, esc_attr gives out the $link. Change the whole bp_core_get_username( ...


0

The previous answer was great as far as the order, but I could not figure out how to make the filter/hook work with those intructions. My solution was creating a custom plugin containing the filter on it, making sure that it alphabetically comes before the plugin that contains the filter I want to add. In other words, put the code in ...


4

If you need to: page the query retain 12 posts per page instead of "sticking" the desired posts on top of the required 12 only need to show those posts on the first page you can try the following $ids_args = [ 'post_type' => 'products' 'posts_per_page' => -1, 'orderby' => 'meta_value_num', 'meta_key' => ...


4

We could do that with two queries: First we fetch the post ids we need with the first query and then we merge it with our sticky post ids and feed it into the second query, using the post__in parameter for filtering and ordering: $args = [ 'post_type' => 'products' 'posts_per_page' => 12, 'orderby' => ...


1

This line in functions.php is your problem: $cat_id = get_post_meta($_REQUEST['cat']); I think you are misunderstanding the purpose of the get_post_meta() function. It is designed to get metadata for a WordPress Post, not data from a POST request to the site. The first parameter of the get_post_meta() function is the $post_id, but since you are passing ...


0

Use php Anonymous functions: $my_param = 'my theme name'; add_filter('the_content', function ($content) use ($my_param) { //$my_param is available for you now if (is_page()) { $content = $my_param . ':<br>' . $content; } return $content; }, 10, 1);


3

This allows for the message to be overwritten specifically for the loggedout message while leaving all other messages alone. Here is more documentation on the filter. add_filter( 'wp_login_errors', 'my_logout_message' ); function my_logout_message( $errors ){ if ( isset( $errors->errors['loggedout'] ) ){ $errors->errors['loggedout'][0] = ...


1

Based on Sven's recommended solution and Tom J Nowell's warning about gettext() (see comments for both), I've fashioned the following solution: add_filter( 'login_message', 'wpse_215289_custom_logout_message' ); add_action( 'login_head','wpse_215289_custom_login_head' ); // Detect logout and add custom message. function wpse_215289_custom_logout_message() ...


0

You only want to add a class name based on the counts. Your above code looks like you may have copy/pasted from somewhere but you don't need all that. I just tested this with wp_generate_tag_cloud_data (#L869) and wp_tag_cloud() and it's working. Unfortunately for a basic test site like mine, the small count represents the largest number of tags for me. ...


0

I had exactly the same problem and I found a quite neat solution for it. When investigating, how Wordpress exactly handles the "Private-404" I found, that the post in question is in the queried_object. So you can actually check for that. Therefore in your 404.php do the following: $queried = get_queried_object(); if (is_a($queried, 'WP_Post') && ...


0

Create a function with the needed arguments that returns a function. Pass this function (anonymous function, also known as closure) to the wp hook. Shown here for an admin notice in wordpress backend. public function admin_notice_func( $message = '') { $class = 'error'; $output = sprintf('<div class="%s"><p>%s</p></div>',$class, ...


0

upgrader_post_install has three parameters $response, $hook_extra and $result which give you extra information. At the moment I can't take a look myself, but I'm assuming that especially the $result variable should give you additional information to differentiate.


0

Your answer is perfect working in the first array lvl, for example: $args['meta_query'][] = array( 'key' => 'tour_itinerario_ciudades_repeater_%_tour_ciudades_nombre', '_key_compare' => 'LIKE', 'value' => 'MEXICO', 'compare' => 'LIKE', ); I need do some modifications for work in the second lvl in the array: $args['meta_query'][] = ...


2

I think you are on the right track, but that last part is messy. You are using the bw_add_markup_class function for two different purposes : to return the classes that you want to add to list the context of the filters that you want to call If I understand well want you are trying to do, you need a function to return the array and then apply your ...


0

Thanks, will do next time. I figured this one out: function my_custom_wc_api_order_response( $order_data, $order, $fields ) { $customer_info = get_post_meta( $order->id, '_customer_info', true ); $order_data['payment_details']['customer_info'] = $customer_info; // Apply filters if necessary if ( $fields ) { $order_data = ...


1

Because you only return $content from inside your if - you should always return it: function beschreibung_kriterien( $content ) { if ( is_page_template( 'template-test.php' ) ) { $content .= '<h2>Test</h2>'; } return $content; } add_filter( 'the_content', 'beschreibung_kriterien', 5 ); This just goes to the show the ...



Top 50 recent answers are included