Forum Replies Created

Viewing 15 replies - 1 through 15 (of 26 total)
  • Forum: Hacks
    In reply to: Need Help on WP_Query
    Thread Starter yekxmerr

    (@yekxmerr)

    Soz i’m a noob. Forgot the get_previous_post!

    Solved

    Thread Starter yekxmerr

    (@yekxmerr)

    Thanks for the input, but i was looking for an expert opinion.

    Thread Starter yekxmerr

    (@yekxmerr)

    Ok, i’ve read some SQL because i was a bit rusty and i got the queries. After that i export it to CSV and then edit it manually. Now i don’t know how to upload the file because it lists only the post titles.

    Thread Starter yekxmerr

    (@yekxmerr)

    Alchymyth you’re amazing!
    It work, and it seems not to affect the pagination.
    Thank you for helping me out.

    Thread Starter yekxmerr

    (@yekxmerr)

    The thing is $popular_loop displays the most viewed posts and the main loop displays the normal posts, without the most viewed ones from the $popular_loop. The code above is updated to query_posts, but it’s the same thing.

    Thread Starter yekxmerr

    (@yekxmerr)

    Here you go, i solved it with query_posts but the archive.php is similar to the index file so the problem will persist.

    https://pastebin.com/Kvk2k8gD

    Thread Starter yekxmerr

    (@yekxmerr)

    It works if i use the query_posts on main loop:

    <?php query_posts(array('post__not_in'=>$do_not_duplicate));
     if (have_posts()) : while (have_posts()) : the_post();
     ?>

    Can’t understand why my way didn’t work.

    Thread Starter yekxmerr

    (@yekxmerr)

    Ok after some hours i got this working:
    Wp_query:

    <?php  $cat_ID = get_query_var('cat'); $popular_loop = new WP_Query('cat='.$cat_ID.'&showposts=3&v_sortby=views');
        if( $popular_loop->have_posts() ): while( $popular_loop->have_posts() ): $popular_loop->the_post(); $do_not_duplicate[] = $post->ID; ?>

    Main Loop:
    <?php if (have_posts()) : while (have_posts()) : the_post(); if(in_array($post->ID, $do_not_duplicate)) continue; ?>

    Thread Starter yekxmerr

    (@yekxmerr)

    I’m still working on this and i can’t get it done.
    It is a category.php theme file and i have a normal loop to display the category posts, and now i need a wp_query to show the popular posts of the same category, but this wp_query is displayed first (don’t know if this matters).
    Getting killed on this lol

    Thread Starter yekxmerr

    (@yekxmerr)

    I still can’t get there. Damn this isn’t easy but i won’t rest until i get this to work. The problem is my lack of skills in php ??
    I still can’t get the category id from the main loop, and avoid the duplicate issues on the wp_query.
    Simple Mode On:

    – Query1( Wp_query that lists the 4 most popular posts of the main loop category, avoiding the duplicate on the main loop )
    &
    – Query2 ( Main Loop that lists the posts from the current category and i have a pre_get_posts hook that forces it to list 36 posts per page and it needs to avoid duplicated content from the wp_query )

    Thread Starter yekxmerr

    (@yekxmerr)

    Update: The problem i’m facing now is that i need to create a WP_query that gets the top 4 most viewed post (this i know how) and in the category of the main loop (this i don’t).
    So i need to extract the category id or something from the main loop into a variable and then get it in the wp_query? Or there is a simple way to achieve this?

    Update2:
    I used this on the main loop:
    <?php global $post; if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; ?>
    And this on the wp_query:

    <?php $popular_loop = new WP_Query(array('v_sortby' => 'views', 'v_orderby' => 'desc', 'posts_per_page' => '4', 'cat' => $post>category_id));
        if( $popular_loop->have_posts() ): while( $popular_loop->have_posts() ): $popular_loop->the_post(); $do_not_duplicate = $post->ID; ?>

    But right now i get the data backwards but i think i can fix it. Are the queries ok?

    Thread Starter yekxmerr

    (@yekxmerr)

    Ok i’m using now the pre_get_posts and wow it’s awesome. But this still doesn’t solve my problem.
    $query->set( 'cat', '-5' );
    I would need it to use the current category but i don’t know how to achieve this. I think i need to call $args but i’m not shure.

    And i have another problem, i have this wp_query

    <?php $popular_loop = new WP_Query( array('v_sortby' => 'views', 'v_orderby' => 'desc', 'posts_per_page' => '4' ));
        if( $popular_loop->have_posts() ): while( $popular_loop->have_posts() ): $popular_loop->the_post(); ?>

    But this code will call out all the posts and i need to get the popular ones on the category i’m currently on.
    Sorry for asking this questions, these are probably WordPress dummy stuff

    Thread Starter yekxmerr

    (@yekxmerr)

    Sorry for not being very specific. My problem is that i want to exclude posts on the main loop, and this posts are in a wp_query.
    Example:
    In my category template i show the top 5 popular posts across the pages, and i want to avoid duplicated content on the main loop.

    Same here.
    If i had 2 websites on my vps i think i could crash the server rack lol. It only gives me problems when i log to the administration and ff i stay out of it the site is ok. When i need to post or do anything in the administration i deactivate the plugin (sometimes it isn’t an easy task).
    Waiting for a fix.

    Thread Starter yekxmerr

    (@yekxmerr)

    Ok i’ve discovered that it isn’t a template issue and i tweaked my code using the codex.
    Thanks anyway.

Viewing 15 replies - 1 through 15 (of 26 total)