Mostrar Posts Relacionados Aleatoriamente en Videos

  • Autor Autor NetReyes
  • Fecha de inicio Fecha de inicio
N

NetReyes

Eta
Hola,

Como estan colegas. Bueno espero me echen su ayuda ya que no e logrado hacer esta funcion. Mostrar los post relacionados de un post type de manera aleatoria, ya que el que actualmente tengo me muestra solo los ultimos post de el post type.

PHP:
<?php
$related = get_posts( array( 'post_type' => 'videos', 'numberposts' => 4, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) {
setup_postdata($post); 
?>
<div class="videos">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div>
<?php }
wp_reset_postdata(); ?>
 
Y si usas el pluging de jetpack te muestra de forma aleatoria 3 tanto en imagen como en texto, es cuestión de probarlo haber si te gusta:encouragement:
 
Hola.

Si solo te falta hacerlo aleatorio, entonces te faltaría enviar orderby=rand en los parámetros.

PHP:
$related = get_posts( array( 'post_type' => 'videos', 'numberposts' => 4, 'post__not_in' => array($post->ID), 'orderby'=>rand ) );
 
Atrás
Arriba