New answers tagged

0

Yes, these are probably the right calls to use for what you want. I just checked this by adding this to my functions.php: add_action('publish_to_draft', 'doStuff'); function doStuff() { update_option('foo', 'bar1'); } Then using the quick edit in the posts list to change a published post to draft, and this hook definitely ran at that point and set this ...


0

I figure out this by changing the following code from compare.php in Yith Plugin. <?php foreach ($fields as $field => $name) : ?> <th> <?php if ($field != 'image') echo esc_html( $name); ?> </th> . . . Changed to this => <?php foreach ($fields as $field => $name) : ?> <th> <?php if ($field != 'image') ...


0

I got fixed my problem by using the method prepare_item_for_response in WP_REST_Terms_Controller function custome_posts_response(WP_REST_Response $data, WP_POST $post, WP_REST_Request $request) { $newspapers = wp_get_post_terms($post->ID, 'newspaper'); $categories = wp_get_post_terms($post->ID, 'category'); $tags = wp_get_post_terms($post-&...


0

Based on "BenCole" answer: date() is affected by runtime timezone changes which can cause date/time to be incorrectly displayed. better to use WordPress native current_datetime() that "retrieves the current time as an object with the timezone from settings". $current_time = current_datetime()->format( 'Hi' ); $...


1

You don't need $url = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; for getting the current URL to remove the query string. All you need is remove_query_arg('the_query', false). False, means it will use the current URL and your code can be shorten to: function abc_redirections(){ if(isset($_GET['query_string']) || isset($_GET['...


0

It's important to read the documentation for filters. The documentation for pre_get_document_title says (emphasis mine): Filters the document title before it is generated. and $title (string) The document title. Default empty string. So when using pre_get_document_title, the title has not been set yet, so when you do this: return $title . ' new title'; ...


3

The parent theme's functions.php runs after the child theme's, so in order to remove an action defined by the parent theme the remove_action call must be delayed using a hook after the parent theme registers the action. So putting the remove_action call purely inside the child's functions.php won't work. It must be attached to a hook. However from the code ...


1

Inside your remove_parent_actions_filters() function, add a test to see if the parent theme's function has been loaded. Maybe you are calling your hook too soon. add_action( 'init', 'remove_parent_actions_filters' ); function remove_parent_actions_filters() { if (!function_exists('fwp_archive_header')) {wp_die("fwp_archive_header function is not ...


0

In my OOP solution I simply used a class member variable which is called in the callback function. In this example the post_title is filtered by a searchterm: class MyClass { protected $searchterm = ''; protected function myFunction() { query = [ 'numberposts' => -1, 'post_type' => 'my_custom_posttype', 'post_status' => '...


1

So you're half way there with the code you have, you're only missing a small part which is that your filter function takes information about what it's filtering through function parameters, can then make changes to the thing that's being filtered (or not) and then must pass that back out (return it). I.e. In this case if for some reason your code decided ...


0

Found it! global $woocommerce; $shipping_method = $_POST['shipping_method'][0]; $shipping_amount = $woocommerce->cart->get_shipping_total();


2

For attachment posts, the following should do it, i.e. use the wp_insert_attachment_data hook along with get_post(): function my_random_post_id( $data, $postarr ) { // Runs if the post is being created and not updated. if ( empty( $postarr['ID'] ) ) { // Locate a yet-unused ID in the (wp_)posts table. do { // Based on ...


0

Just to add on top of what @Jacob Peattie said: the do_action is already in the EDD code somewhere, you don't have to add that part. That's the point that you your new function will get called from. Wordpress takes care of wiring up the two things for you, as per the docs link in Jacob's post. As you wrote in your post, you need to add the add_action to your ...


0

You don't put do_action() anywhere. The plugin runs that when that action occurs. You just need to hook into it with add_action(). The way hooks work is documented here. If you're not sure when or how a plugin's own hooks, such as this one, are fired, then you'll need to contact the plugin developer, or consult its developer documentation.


Top 50 recent answers are included