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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jerry MillerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.