wordpress js php please help

thanks for any help in advance :)

what im trying to do and im not sure if this is even the right bits of code but i want to make a second function that will assign a graphic to a certain post with the id = 12.....
as you can see below i have tried but without success...

the first one is the one that works and the second is the one i need to post to where id =12

any help will be awesome ty


function WPSetAsThumbnail(id, nonce){
      var $link = jQuery('a#wp-post-thumbnail-' + id);

      $link.text( setPostThumbnailL10n.saving );
      jQuery.post(ajaxurl, {
            action:"set-post-thumbnail", post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie)
      }, function(str){
            var win = window.dialogArguments || opener || parent || top;
            $link.text( setPostThumbnailL10n.setThumbnail );
            if ( str == '0' ) {
                  alert( setPostThumbnailL10n.error );
            } else {
                  jQuery('a.wp-post-thumbnail').show();
                  $link.text( setPostThumbnailL10n.done );
                  $link.fadeOut( 2000 );
                  win.WPSetThumbnailID(id);
                  win.WPSetThumbnailHTML(str);
            }
      }
      );
}

function WPSetAsThumbnail22(id, nonce){
      var $link = jQuery('a#wp-post-thumbnail-' + id);

      $link.text( setPostThumbnailL10n.saving );
      jQuery.post(ajaxurl, {
            action:"set-post-thumbnail", post_id: 12, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie)
      }, function(str){
            var win = window.dialogArguments || opener || parent || top;
            $link.text( setPostThumbnailL10n.setThumbnail );
            if ( str == '0' ) {
                  alert( setPostThumbnailL10n.error );
            } else {
                  jQuery('a.wp-post-thumbnail').show();
                  $link.text( setPostThumbnailL10n.done );
                  $link.fadeOut( 2000 );
                  win.WPSetThumbnailID(id);
                  win.WPSetThumbnailHTML(str);
            }
      }
      );
}
LVL 1
Rcollins207Asked:
Who is Participating?
 
Jerry MillerConnect With a Mentor Commented:
Try declaring a variable and assigning it the value that you want.
function WPSetAsThumbnail22(id, nonce){
      var $link = jQuery('a#wp-post-thumbnail-' + id);
      var $myVar = 12;

      $link.text( setPostThumbnailL10n.saving );
      jQuery.post(ajaxurl, {
            action:"set-post-thumbnail", post_id: $myVar, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie)
      }, function(str){
            var win = window.dialogArguments || opener || parent || top;
            $link.text( setPostThumbnailL10n.setThumbnail );
            if ( str == '0' ) {
                  alert( setPostThumbnailL10n.error );
            } else {
                  jQuery('a.wp-post-thumbnail').show();
                  $link.text( setPostThumbnailL10n.done );
                  $link.fadeOut( 2000 );
                  win.WPSetThumbnailID(id);
                  win.WPSetThumbnailHTML(str);
            }
      }
      );
}

Open in new window

0
 
Rcollins207Author Commented:
mmm not sure why but it does seem to be working... and no error aaar frustration lol
0
 
Jerry MillerCommented:
I think that it is because php was trying to interpret the 12 instead of using its value. When you declare a variable and assign a value, php can interpret it normally.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.