• Resolved Philip

    (@artdev)


    hi to the wp members,

    i’m building a custom widget that will call one post from a custom post type,

    i use this query to call the post but for some reason it returns a different/wrong post,

    query_posts("post_type=myptname&p='.$post.'&posts_per_page=1");
    if ( have_posts() ) : while ( have_posts() ) : the_post();

    i have try to add &order=ASC and orderby=menu_order
    but none of this returns the correct post

    does anyone here knows how i can fix this?
    is this query correct to use it in a custom widget or i have to build a different query?

    thanks a lot,
    Philip

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    $id_of_post =  123;
    $args=array(
      'p' => $id_of_post,
      'post_type' => 'myptname',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Adding order and orderby for retrieving just one post wouldn’t be necessary.

    Thread Starter Philip

    (@artdev)

    thanks a lot MichaelH,

    it was a problem with my taxonomies i fix it now.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Run a query in a custom widget?’ is closed to new replies.