Skip to content

Instantly share code, notes, and snippets.

View serkanalgur's full-sized avatar
🇹🇷
Selam / 🇦🇿 Salam / 🇬🇧 Hi!

Serkan Algur serkanalgur

🇹🇷
Selam / 🇦🇿 Salam / 🇬🇧 Hi!
View GitHub Profile
// Get user IP in WordPress
function get_the_user_ip() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
//check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
//to check ip is pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
$args = array(
//Sayfa ve Yazı parametreleri
'p' => 1,
'name' => 'hello-world',
'page_id' => 1,
'pagename' => 'sample-page',
'post_parent' => 1,
'post__in' => array(1,2,3),
'post__not_in' => array(1,2,3),
// Sorgu
$the_query = new WP_Query( $args );
// Loop Döngüsü
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
@serkanalgur
serkanalgur / gist:3783555
Created September 25, 2012 18:23
function for comments shortcode
function phpcode($atts, $content = "") {
return '<pre class="php">'.esc_attr($content).'</pre>';
}
function csscode($atts, $content = "") {
return '<pre class="css">'.$content.'</pre>';
}
function htmlcode($atts, $content = "") {
return '<pre class="html">'.esc_html($content).'</pre>';
}
function init_common_shortcodes() {