Display random page

The first condition you list is easy. You just need the post_parent__in arguments. $args = array( ‘post_type’ => ‘page’, ‘posts_per_page’ => 1, ‘orderby’ => ‘rand’, ‘post_parent__in’ => array(2,169), // replace with your IDs ); $rand = new WP_Query($args); if ($rand->have_posts()) { while ($rand->have_posts()) { $rand->the_post(); the_title(); echo ‘<br>’; } } For the second condition, I … Read more

Problem retrieving custom field for a custom post type

The solution is simple: in the first loop, you are setting the $amazon_link like this: $amazon_link = get_field(‘amazon_link’, $image[‘ID’]); but in the second loop, you are setting a $link, like this: $link = get_field(‘amazon_link’, $image[‘ID’]); but you’re still trying to echo $amazon_link variable later on, which has never been setup in the second loop, so … Read more

How to implement template file and the loop

I have seen that there is extra (); so maybe this syntax error prevent display in front-end please try below code – <?php /** * Template Name: Basic Test */ get_header(); if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title(); endwhile; else : _e( ‘Sorry, no posts matched your criteria.’, ‘textdomain’ ); … Read more

What is the advantage of using home.php over index.php for the front page

If you look here [is_home vs is_front_page] you’ll see that is_front_page() is true regardless of what the homepage is set to in the WordPress settings. This means that if you don’t plan on releasing this publicly (i.e. short-run usage) then just having a front-page.php should suffice. is_home() is set based on your blogs page (which … Read more

AJAX requests within templates

Security through obscurity isn’t a good pattern to follow. You have to have a URL to make XHR or JSONP calls. Anyone who knows anything about searching the DOM using developer tools, Firebug, etc… can easily find your remote script URL. To me, this is the wrong question to ask. The more relevant question to … Read more

load_textdomain won’t load my .mo file

I found the answer: load_textdomain( ‘site-map’, TEMPLATEPATH.’/partials/languages’ ); … gives the path of the folder containing the .mo file. but the path of every individual mo file should be used in its own load_textdomain instruction : load_textdomain(‘site-map’, TEMPLATEPATH.’/partials/languages/site-map-fr_FR.mo’); load_textdomain(‘site-map’, TEMPLATEPATH.’/partials/languages/site-map-en_US.mo’); load_textdomain(‘site-map’, TEMPLATEPATH.’/partials/languages/site-map-es_ES.mo’); load_textdomain(‘site-map’, TEMPLATEPATH.’/partials/languages/site-map-ru_RU.mo’); load_textdomain(‘site-map’, TEMPLATEPATH.’/partials/languages/site-map-de_DE.mo’); Shame on me it is a very obvious and … Read more

How to make a template for a specific post of a custom post type?

As Pages are a special built in Posttype, they get an own template hierarchy. Other “normal” post types and custom post types can only be templated by “single-$posttype.php”. You can however hook into the single_template filter and make wordpress redirect to your template file: function get_custom_post_type_template($single_template) { global $post; if ($post->post_type == ‘account’) { $located … Read more