How to declare a JS variable in an AJAX call

The right way is to post the data back to the WordPress admin ajax url then in your PHP function access them using the $_POST variables. Example jQuery function that passed a category id back to wordpress: function cat_edit_get() { jQuery( “#loading-animation”).show(); var catID = jQuery(“#cat :selected”).val(); var text = jQuery(“#cat :selected”).text(); jQuery(‘#replace’).html(text); jQuery.ajax({ type: … Read more

How do you Query posts with nothing in common?

Maybe you’re looking for the post__in parameter in WP_Query. $query = new WP_Query(array( ‘post__in’ => array(23,18,2,199,6,8) ); And then: while ( $query->have_posts() ) { $query->the_post(); /* post loop */ } Take a look at the docs. =D For public queries: post__in is not public queryable by default, so you can just validate and copy $_GET[‘post__in’] … Read more

Admin: global $post empty

The basic mistake is, that every data is available at the point where you write your code. That isn’t the case and hooks are there to provide access to the core code during different states of the core loading procedure graph. In short and very simplified things run like this: # core loads // …more … Read more

When would you use $_post instead of $post?

I’m not certain, but if you’re talking about $_post as seen here: http://codex.wordpress.org/Function_Reference/in_category It’s referring to a post ID so they’ve probably added the underscore to avoid confusion. The $post variable is a post object with all the details of the post. However, $_POST is a global PHP variable containing all the values sent from … Read more

Replacing string with a variable in php

There are 4 valid ways of defining a string, see this question for more details. However in your case there is a special exception provided by PHP. Most users are unaware of it however, and it does leave ambiguities, as it’s no longer possible to tell a string literal, a constant, or a define apart, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)