WordPress.org

Ready to get started?Download WordPress

Forums

Filter Comments via Query String (6 posts)

  1. meno19
    Member
    Posted 2 years ago #

    I have a page enabled with comments. Their is a query string that is associated with this page. How would I be able to filter what comments to show based on a query string?

  2. Peter_L
    Member
    Posted 2 years ago #

    Can't you use the default wordpress comment handling?
    http://codex.wordpress.org/Function_Reference/wp_list_comments

  3. meno19
    Member
    Posted 2 years ago #

    Yes I am using the default comment handling but this is my situation.

    I have a page that the content changes based on the query string that is passed to it. So think of a Product Detail Page. It is the same individual WordPress page but different content based on the query string.

    So I would like to use the default comment handling for writing and storing posts, but when the page loads I only want to show the comments that are for that product.

    Idea would be to select all of the comments for that page and then only show the ones that are associated with the query string that I pass to it.

  4. Peter_L
    Member
    Posted 2 years ago #

    Why don't you use posts? (if necessary custom post types). Then you can get one post/product and use the default comments.

    Oh, and as for your problem, sorry no idea. I'd say, if it's a query string you could get it with php $_GET.

    But, it just sounds weird to me. It's like building a custom CMS system on top of WP...

  5. meno19
    Member
    Posted 2 years ago #

    Sorry I may not be explaining quite right.

    What I am doing is I have a Plugin that creates a search engine functionality for a set of products that are loaded into its own table. I will have thousands of products in the table. The search engine page searches via a custom search and generates the list of products. If a user clicks on a result it takes you to the product detail page which is a standard wordpress page. The overall shell of the page is a template but the data loaded in it is dependent upon the query string that is sent over in the URL.

    So I have the pages loading fine, I get the query string and query the data for that product.

    What I am trying to do is enable comments on that page. That is easy enough as comments can just be enabled but the comments will be recorded at the page level with no regard to the query string.

    I overcome this by also posting the query idea to the comments meta data table. This allows me to associate the comment with the query id. All I have to do now is filter the comments so that only the comments for that item display on the page.

    Trick is how can I filter the comments as they get queried to the page.

    Let me know if that made more sense.

  6. Peter_L
    Member
    Posted 2 years ago #

    Not sure about this. What I would look into:

    http://codex.wordpress.org/Function_Reference/get_comments

    This gets you an array of all the comments. This is a php array so you can process it with php using the variables from your query string.

Topic Closed

This topic has been closed to new replies.

About this Topic