Я запускаю простой запрос, который отображает некоторые сообщения в настраиваемом типе сообщений.
Через каждое сообщение в этом типе сообщения я добавил флажок ACF True / False. Если флажок отмечен, я бы хотел, чтобы этот пост появлялся только в том случае, если вы находитесь в США.
Вот что я до сих пор:
<?php // Begin loop while ( have_posts() ) : the_post(); ?> <article> <?php // If within the USA if(get_field('usa')) { ?> <?php // Query post $args = array( 'post_type' => 'projects', 'posts_per_page' => 12 ); $get_projects = new WP_Query( $args ); while ( $get_projects->have_posts() ) : $get_projects->the_post(); ?> <section> <header class="entry-header"> <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?> </header><!-- .entry-header --> <?php the_content(); ?> </section> <?php // End query post type endwhile; wp_reset_postdata(); ?> <?php } // end if else { // The rest of the world ?> <?php // Query post $args = array( 'post_type' => 'projects', 'posts_per_page' => 12 ); $get_projects = new WP_Query( $args ); while ( $get_projects->have_posts() ) : $get_projects->the_post(); ?> <section> <header class="entry-header"> <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?> </header><!-- .entry-header --> <?php the_content(); ?> </section> <?php // End query post type endwhile; wp_reset_postdata(); ?> <?php } // end else ?> </article> <?php endwhile; // End loop ?>
Правильно ли я полагаю, что мне нужно будет добавить к запросу США, указав определенный диапазон IP-адресов? Я не мог найти ничего с помощью условных тегов в кодексе.
Взгляните на freegeoip.net . Например, я использовал его с помощью jquery.
$.get( "http://freegeoip.net/json/", 'jsonp', function( data ) { country = data['country_code']; if( country == 'US' ){ // show your content }; });