Why get_posts() not returning only selected category posts from Custom Post Type?

First, your custom post type is portfolio-item, not portfolio_item. Note that you register the post type with $this->base name and previously you did $this->base=”portfolio-item”;. Also, numberposts is obsolete, use post_per_page instead: $args = array( // ‘post_type’ => ‘portfolio_item’, ‘post_type’ => ‘portfolio-item’, ‘orderby’ => ‘rand’, ‘post_per_page’ => 1 ); Then, the taxomy argument of your query … Read more

Creating a Multi-Level Associative Object Using AJAX

If you want to pass a complex value, your best path is probably to jsonify it. Something like $.post( MyAjax.ajaxurl, { action: ‘my_action’, someValue: JSON.stringify({ one: ‘Some Value One’, two: ‘Some Value Two’, three: ‘Some Value Three’, four: ‘Some Value Four’, }) } ); and then on the server side you decode the value with … Read more

WordPress Ajax Not Working ( Custom Admin page)

Uncaught TypeError: Cannot read property ‘ajax’ of undefined @Sasa1234, it happen cause your jQuery is undefined. Please take a look @EAMann answer. So, your JS code should like this: function myajaxfunction() { if ( undefined !== window.jQuery ) { jQuery.ajax({ //ajax request url: ajaxurl, data: { ‘action’:’rs_like_request’, ‘post_type’ : jQuery(‘#post_type’).val() // value of text box … Read more

Load a page into a div with Ajax

My philosophy is that if you use a system like WP then you embrace it and do things the WP way. WP has plenty of hooks that let you override functionality and the flexible theme structure gives you almost total control over the output. So, I’d advise using a WP theme and WP built in … Read more

ajax nonce verification failing

To verify nonces in Ajax requests, check_ajax_referrer() should be used instead of wp_verify_nonce(): Crete the nonce: $nonce = wp_create_nonce( ‘vote-nonce-‘ . get_the_ID() ); Include it in JavaScript: jQuery(document).ready(function(){ jQuery(“.post-voting”).click(function(){ vote_nonce = <?php echo $nonce; ?> vote_id = jQuery(this).data(‘vote-id’); jQuery.post( vote_ajax.url, { action: ‘submit_vote’, vote_id: vote_id, vote_nonce: vote_nonce }, function( data ) { alert( jQuery.parseJSON(data) ); … Read more

AJAX response, edit tags

Wait for WordPress 4.7 on 6th December. It has this almost built-in. If I got it right, then you’ll want to prevent some terms from deletion. I already made a snippet for that which works with WP 4.7 add_filter( ‘user_has_cap’, function ( $allcaps, $caps, $args ) { if ( ! isset( $args[0] ) || ‘delete_term’ … Read more