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 believe you need a filter. WP_Query
cannot handle that logic natively, so far as I know.
function restrict_post_name_wpse_130401($where) {
remove_filter('posts_where','restrict_post_name_wpse_130401');
return $where.' AND post_title != "Contributors"';
}
add_action('posts_where','restrict_post_name_wpse_130401');
$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>';
}
}
Used exactly as above this should work fine. That is, if you add the filter immediately before your query it will run and remove itself, effecting only the one query.