do_action Nested List

If you want to return a value in your hook, use apply_filters instead of do_action, like: $project_option .= ‘<ul class=”project-list”>’; foreach( $projects as $project ) { $project_id = $project->ID; $project_option .= ‘ <li class=”project” id=”project-‘ . $project_id . ‘”> <span class=”project-title”>’ . get_the_title( $project_id ) . ‘ </span> <span class=”project-status-title”>’ . __( ‘Project Status: ‘, … Read more

the_post hook is not firing for me

Assuming that your post_meta is being properly added, that the post in question is a real post, and that the value of ‘nb_postredirect’ is a good URL, I’d try: function nb_checkredirect( $post ) { //don’t have to use get_post_meta!* if ( $post->nb_postredirect ) { wp_redirect( $post->nb_postredirect ); exit; } } add_action( ‘the_post’, ‘nb_checkredirect’ ); Tested … Read more

AMP – Change rel=”canonical” from functions.php [closed]

In general you can deregister the action’s callback, after it’s been registered and then register your own before it’s invoked with do_action( ‘…’ ). Here’s an example: // Add your own with later priority, e.g. 11 or wrap it in another later hook: add_action( ‘amp_post_template_head’, ‘wpse_amp_post_template_add_canonical’, 11 ); function wpse_amp_post_template_add_canonical( $amp_template ) { // Remove … Read more

Form action unfamiliar

Generally, they will return the same URL, as bloginfo( ‘url’ ) will call home_url internally with any arguments, and the default first argument ($path) of home_url is the empty string. However, bloginfo( ‘url’ ) will apply an additional filter to it, namely the home_url filter. Common pratice is to use home_url, indeed with esc_url (even … Read more

Filter for when the post is updated

The filter you are looking for is save_post. This filter is triggered each time you save a post. add_action( ‘save_post’, ‘my_function’ ); function my_function( $post_id ){ // Do your stuff here } This filter passes the post’s ID to the callback function, so you have access to everything you need.

Submit Form data to another page via Ajax (WordPress Way)

Modify the following code I have added action in it. $(‘#btnDoCalculation’).click(function(e){ var formData = $(‘#interest_calculator’).serialize(); $.ajax({ type: ‘POST’, url: ‘<?php echo admin_url(‘admin-ajax.php’);?>’, data:formData, dataType: ‘json’, action:calculate_investor_interest encode:true, }).done(function(data){ if(data.success){ console.log(data); var results = data.calc_results; var newData = results.reduce(function(collection, element){ var rowData = {}; //create a new empty row element.reduce(function(collection, element){ //put the elements into the … Read more