How to clone all WordPress Rest API end points

There is nothing wrong if API returns more than what you need. Unless there is a security/privacy issue it is unlikely that the additional info will matter. If you totally can not live with core’s API, you need to just write your own. “cloning”, “forking” or any other nice term you might want to use … Read more

Send checkbox status with Ajax / JSON and save it

.prop() method return boolean type. True or false. You should send checked value and save it into database. And in HTML get your value and set it to your checkbox. An example you have <input type=”checkbox” name=”test” class=”checkbox” value=”checked”>. You should send to php $(‘.checkbox’).val(); and then place checked attr to html. <?php $checked = … Read more

Full Front End, AJAX comment system and comment reply script

<script> var addComment = { settings: function( parentId, postId ) { var t = $(this), commentDivName = $(‘#comment-‘+parentId), formDivName = $(‘#commentForm-‘+postId), formReplyDivName = $(‘#commentReplyForm-‘+parentId), postDivName = $(‘#post-‘+postId), theform = formDivName.find(‘form.comment-form’); if( !t.length || !commentDivName.length || !formDivName.length || !postDivName.length ) { return; } if(!theform.length){ $(postDivName).find(‘[id^=commentReplyForm-]’).each(function(){ if($(this).find(‘form.comment-form’).length){ formDivName = $(‘#’+$(this).attr(‘id’)); } }); theform = formDivName.find(‘form.comment-form’); } theform.find(‘input[name=parent]’).val(parentId); … Read more

entire JS folder not loading in a WP theme

The problem is die(). You can’t die() inside a template or it will stop the entire site loading at that point. If you looked closer you’d notice that it wasn’t just the JS folder that wasn’t loading, it was the whole footer. You need to separate you code into 2 functions. One that outputs the … Read more

How to display partial values of JSON Encode values

Use json_decode: global $wpdb; $project_member_details = $wpdb->get_var( $wpdb->prepare( “SELECT project_members FROM wpxa_orocox_project_members WHERE project_id = 603” ) ); $project_member_details = json_decode( $project_member_details, true ); print_r( $project_member_details[‘member_image’] ); If you still want the output to be JSON encoded at the end of it, you could then do something like: $member_images = $project_member_details[‘member_image’]; echo wp_json_encode( [ ‘member_image’ … Read more

URL rewrite with external JSON query

You can try URL rewriting like that add_action(“wp_loaded”, function () { add_rewrite_tag(“%id%”, “([^&]+)”); add_rewrite_rule( ‘^details/[^&]+/([0-9]+)/?’, ‘index.php?id=$matches[1]&pagename=details’, ‘top’ ); }); And then flush rewrite rules cache one time in Settings -> Permalinks. With this rewriting, the identifier is no more in $_GET but you can get it with https://codex.wordpress.org/Function_Reference/get_query_var.

How can I wp_send_json data?

It seems wp_send_json_success works! I just did something very wrong with it. When you hit the AJAX endpoint, at the end of the logic, simply: wp_send_json_success( [‘next_step’ => ‘enpoint_2’], 200 ); This will send an object to JS: Object{next_step: ‘endpoint_2’} Which you can then use to further your process.

Run shortcode in custom script in wp_head if post type is CPT ‘Jobs’

You shouldn’t do it in a shortcode, you should enqueue this particular JavaScript file only for the page you want. Place something like this in your functions.php: function my_custom_scripts() { if( is_singular(‘job’) ){ wp_enqueue_script(‘jobpostingschema’, get_stylesheet_directory_uri() . ‘/js/jobpostingschema.js’, array(), ”, false); } } add_action(‘wp_enqueue_scripts’, ‘my_custom_scripts’);