Support » Plugins » Hacks » I have a doozy…..

  • Resolved mkbclr


    Ok – this is crazy….

    on a single.php i have this

    $query = new WP_Query(

    ‘paged’ => curPageURL(),
    ‘post_type’ => ‘video’,
    ‘order_by’ => ‘date’,
    ‘order’ => ‘desc’,
    ‘cat’ => $cat_ID,
    ‘posts_per_page’ => 18


    ); ?>

    i found that no pagination plugins work on single.php – so i wrote my own using and manipulating the URI based on which page you are currently on.

    My problem is that no matter how many numbers you put after the url, the page still loads. the pagination will say page 11111111111111 of 4. then…. the previous link gets all screwy.

    the real issue is that somehow google has indexed about 18000 of these crazy urls, and they show as crawl errors and we are losing traffic.

    here is a sample url…

    i feel pretty sure it has something to do with the query – but i have no idea what it could be.

    please help!


Viewing 11 replies - 1 through 11 (of 11 total)
  • What does curPageURL() do? Judging from the function-name it returns the url of the current page? If so, the ‘paged’ key only accepts the current page NUMBER, not the URL. Perhaps that is the problem?

    oh yea h- that makes sense 🙂

    how does this look? (it still servers the crazy 11111111111 urls btw)

    <?php function curPageURL() {
    $pageURL = ‘http’;
    //check what if its secure or not
    if ($_SERVER[“HTTPS”] == “on”) {
    $pageURL .= “s”;
    //add the protocol
    $pageURL .= “://”;
    //check what port we are on
    if ($_SERVER[“SERVER_PORT”] != “80”) {
    } else {
    //cut off everything on the URL except the last 3 characters
    $urlEnd = substr($pageURL, -3);
    //strip off the two forward shashes
    $page = str_replace(“/”, “”, $urlEnd);
    //return just the number
    return intval($page);



    $query = new WP_Query(

    ‘paged’ => $page,
    ‘post_type’ => ‘video’,
    ‘order_by’ => ‘date’,
    ‘order’ => ‘desc’,
    ‘cat’ => $cat_ID,
    ‘posts_per_page’ => 18


    ); ?>
    <h3><?php $num = $query->found_posts;
    $totalpages = ceil($num / 18);
    echo $num;?>

    Hmm, I am not sure what the context is in which you try to do this, but if I remember correctly you can display the current page of a pages set like so:

    $query = new WP_Query(
        'paged' => get_query_var('paged'),
        'post_type' => 'video',
        'order_by' => 'date',
        'order' => 'DESC',
        'cat' => $cat_ID,
        'posts_per_page' => 18

    No need to use a custom function to get the current pagenumber.
    Also, where does $cat_ID come from?
    I am however suspecting that your problem resides elsewhere in your code.

    the whole problem came about when i wasn’t able to use pagination on a single.php. that’s when i had to start all this craziness rather than just the plain ole’ use the loop – use a pagination plug like normal.

    $cat_ID is just an if statement so i can control which wordpress category is used.

    you got any idea where i should start looking? i have the standard wordpress stuff in htaccess – and i dont have any other ideas…

    oh, sorry I missed the part about this code being in single.php. That clears up something.
    I don’t think there is a “current page” on a single page (the name says it all) because a single page is just that, single (please correct me if I am wrong). So in order to create a WP_Query on that page showing multiple (I am assuming related to the current page) video’s in pages (it is probably better to speak of “sets” in this case) you probably need to “manually” keep track of the current “set”. Or use the ‘offset’ key

    as if it is not obvious – i am kind of a php / wordpress hack.

    and chance you could help me out with what would work?

    i have never heard of offset, but am reading the link you sent now. i just don’t quite understand yet.

    as best i can tell i should remove the paged key and replace with ‘offset’ => 1

    am i on the right track?

    Perhaps it would help if you try to explain what it is exactly that you want to accomplish?
    The way I understand it is as follows:
    You have a post and when showing that post you want to include video’s on the same page that relate to that post. Is that correct?

    fwiw i put in the offset key and removed paged
    everything works the same – with the crazy urls still serving.

    as for what i am trying to do….
    take a look here –

    Installing Bifold Doors

    this will give you the second page

    everything works like i want it to, but it will still serve these crazy urls ending with a long string of numbers (if you replace the 2 with 111111111111111111 the page will load)

    google has indexed all these crazy urls and it’s causing us trouble. i don’t know how they got to the bad urls, since there is no link to them. you can only get there by typing the numbers in.

    all i want it for those crazy urls not to load a page – a 404 would be nice.

    Can you email me, perhaps we can get more “productive” that way. As long as you post the solution here later when we find it.

    This was resolved thanks to Umbercode – all around good guy

    Here’s his response

    So I did some test on my testsite and found that any single.php page accepts any slug behind it. For example, taking wordpress’s own site if you go to this link:
    is the same as going to this link:

    Bit of a weird behaviour, but it seems to be “normal” so at least it is not something in your code. So as long as you make sure there are no links to any of these strange pages Google will be happy and so will you 😉

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘I have a doozy…..’ is closed to new replies.