Forums

[resolved] Exclude current page from MySQL results (3 posts)

  1. therealOC
    Member
    Posted 3 years ago #

    I have a sidebar that i made that shows some recent posts and am using MySQL to select everything from the table that has a certain post parent.

    On thing that i am trying to do now is exclude the current page from the results. Does anyone know how to do that? Is there a certain place where an $except would go within the MySQL query or the foreach bit of php (e.g. foreach($pages as $page $exceept(8141)):)

  2. whooami
    Member
    Posted 3 years ago #

    foreach($pages as $page $exceept(8141)):

    since thats your "code", and not how a plugin would do this...

    the current page

    if whatever it is youre displaying post-wise isnt paged, you could use an offset.

    If it is a plugin youre using, it would help to know which one.

  3. therealOC
    Member
    Posted 3 years ago #

    Have actually just found a way of doing it that is really easy so i though i would put it up for anyone who is interested. If you need to exclude something such as the ID of the current page from a MySQL statement then just add something like WHERE ID != $post->ID when selecting something something using MySQL. If you don't know your MySQL != stands for not equal too (just in case). Hope this helps anyone else who had this same problem.

Topic Closed

This topic has been closed to new replies.

About this Topic