Created
September 27, 2012 23:29
-
-
Save andresgallo/3797078 to your computer and use it in GitHub Desktop.
printR GET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//The function print_r allows you to print the content of an array | |
//www.domain.com?param1=value1¶m2=value2 | |
print_r($_GET['awesome']); | |
/***HERE IS THE ACTUAL USE OF THIS*****/ | |
$my_id = 5369;//post id | |
$post_id_5369 = get_post($my_id);//my post | |
$content = $post_id_5369->post_content;//content | |
echo $content; | |
/**** THe number could be replaced with ****/ | |
$my_id = $_GET['mypostid'];//post id | |
$post_id_5369 = get_post($my_id);//my post | |
$content = $post_id_5369->post_content;//content | |
echo $content; | |
?> | |
<?php | |
//include the wp_load.php file | |
//The actual idea for post script | |
$my_id = $_GET['mypostid'];//post id | |
$mypostObject = get_post($my_id);//my post | |
$content = $mypostObject->post_content;//content | |
echo $content; | |
?> | |
SOME HTML CODE | |
<a href="ignoreThis.html" data-id="5369">Whatever 5639s title is</a> | |
SOME JAVASCRIPT CODE | |
$('a[data-id]').on('click',function(){ | |
var theId = this.getAttribute('data-id');//We are grabbing whatever number this link has | |
var dataObject = {//If you look below im passing this object to ajax call | |
mypostid : theId,//This is the get parameter the URL in the php file will see | |
someotherParameter : 'HI'//Some other parameter to explain how this works | |
} | |
/*you are passing the above object here and the php script will run. The php will as if the url was this | |
'path/to/my/script.php?mypostid=5369&someotherParameter=HI' */ | |
$.ajax({ | |
url : 'path/to/my/script.php', | |
data : dataObject,//Object passed with url parameters | |
success : function(returnedData){ | |
//Do something with returned content The returned content will be whatever is displayed on the php script | |
}, | |
error : function(returnedData){ | |
//handle error | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment