WordPress.org

Forums

Query Posts syntax (5 posts)

  1. ParamasivanPN
    Member
    Posted 1 year ago #

    Hi,

    In the bought out theme it is like

    if ( is_page() ) {
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        query_posts( 'post_type=post&paged=' . $paged );
    }

    I want to modify the above code to include only category "Collaborations" and not all posts to be displayed.

    How to modify the code?

    Thank you,

  2. The code in the bought out theme isn't using parameterized queries, and could be susceptible to SQL injection:

    So to address that and answer your question, change:

    if ( is_page() ) {
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        query_posts( 'post_type=post&paged=' . $paged );
    }

    to

    if ( is_page() ) {
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        query_posts( array ( 'post_type' => 'post', 'category_name' => 'Collaborations', 'posts_per_page' => 5, 'paged' => $paged ) );
    }

    Big caveat, I wrote this in the forum text area (I haven't tried running it), so I'll make sure it's valid when I get back in front of my work computer.

  3. ParamasivanPN
    Member
    Posted 1 year ago #

    Sorry ; It displays other post categories also (including uncategorized).

  4. OK, looks like you need to use the category slug:

    'category_name' => 'my-category-slug'

    or category id:

    'cat' => 22

    Sorry about that...

  5. ParamasivanPN
    Member
    Posted 1 year ago #

    Sorry, nothing works in this bought out theme.

    The theme author suggested to make the menu (appearance -> menus) to choose the category "Collaboration" as the menu item and it worked.

    http://test.skinnycreative.com/projects/aob/category/collaborations-cat/

Topic Closed

This topic has been closed to new replies.

About this Topic