Skip to content

Instantly share code, notes, and snippets.

@cesjam7
Created November 6, 2021 16:16
Show Gist options
  • Save cesjam7/18d10e9bd07b7e5597a32b9d8fbb7b87 to your computer and use it in GitHub Desktop.
Save cesjam7/18d10e9bd07b7e5597a32b9d8fbb7b87 to your computer and use it in GitHub Desktop.
<?php $categorias = ["alfa", "beta"];
$args = [
'post_type' => 'post',
'posts_per_page' => -1,
'orderby' => 'rand',
'tax_query' => [
'relation' => 'AND',
[
'taxonomy' => 'grupo',
'terms' => ['alfa', 'beta'],
'field' => 'slug',
'operator' => 'AND'
],
[
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'premium'
]
]
];
unset($args['tax_query'][0]['terms'][1]);
if (is_user_logged_in()) {
$user = wp_get_current_user();
$args["author"] = $user->ID;
unset($args["post_status"]); ?>
<h1>Publicaciones de <?php echo $user->display_name; ?></h1>
<?php } else { ?>
<h1>Todas las publicaciones</h1>
<?php }
echo '<pre>'.print_r($args, 1).'</pre>';
$entradas = new WP_Query($args);
//echo '<pre>'.print_r($entradas->query_vars, 1).'</pre>';
if ($entradas->have_posts()) {
$c = 0;
while ($entradas->have_posts()) { $entradas->the_post();
$c++;
echo $c.': '.get_the_title();
echo '<hr>';
} wp_reset_postdata();
} else {
echo '<p>No se encontraron artículos</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment