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’);

Strange “lea” prefix on wp-json

I found it. There’s a bug in the TotalPress.org Custom Post Types plugin in the file: wp-content/plugins/custom-post-types/custom-post-types.php At the top of the file, you will see the mistake: lea<?php When I remove the lea, the problem goes away. I’m contacting the plugin developer to let them know. Plugin version was 3.0.12.

Is there a way I can fetch the WordPress Developer Code References with an API?

It seems to be accessible from: https://developer.wordpress.org/wp-json/wp/v2/wp-parser-class https://developer.wordpress.org/wp-json/wp/v2/wp-parser-method https://developer.wordpress.org/wp-json/wp/v2/wp-parser-hook https://developer.wordpress.org/wp-json/wp/v2/wp-parser-function and search with e.g. https://developer.wordpress.org/wp-json/wp/v2/wp-parser-function?search=get_post_embed but it’s probably best to generate your own with the WP Parser here: https://github.com/WordPress/phpdoc-parser This will create custom post types for wp-parser-hook wp-parser-function wp-parser-class wp-parser-method and related post meta (to e.g. store function input arguments, line numbers, class type, hook … Read more