• Resolved mcrawford620

    (@mcrawford620)


    Is there a way to get a list of pages in a category?

    I have one post in the category, and one page. I’ve tried every combination I can think of with get_posts, but I can only get the post back and never the page.

    get_posts(array('category' => 50, 'page_type' => 'page'))
    get_posts(array('category' => 50))
    get_posts(array('tax_query' => array(array('taxonomy' => 'category', 'field' => 'id', 'terms' => 50))))

    get_pages doesn’t have a category parameter so that doesn’t help.

    Nothing I’ve tried will give me back that page.

    I’m using version 1.3 of the plugin.

    https://ww.wp.xz.cn/plugins/post-tags-and-categories-for-pages/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter mcrawford620

    (@mcrawford620)

    I will note that in the WordPress pages admin section, I can successfully filter by the category.

    /wp-admin/edit.php?s&post_status=all&post_type=page&action=-1&m=0&cat=50&paged=1&action2=-1

    So the plugin is working fine in that case but I can’t seem to get WP_Query or get_posts or anything to give me back what I want.

    Plugin Author curtismchale

    (@curtismchale)

    What version of WordPress are you using?

    Are you running any other plugins that modify WP_Query or use the pre_get_posts filter?

    Thread Starter mcrawford620

    (@mcrawford620)

    Ugh, I knew I would find the right syntax after posting here. This works:

    get_posts(array(
    	'post_type' => 'page',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'category',
    			'field' => 'id',
    			'terms' => 50
    		)
    	)
    ));

    Thanks for the reply, though. WordPress 3.8.3, and I don’t think we’re running anything else that would hook WP_Query, although I didn’t search through all the plugins we have installed.

    Plugin Author curtismchale

    (@curtismchale)

    Glad you got it sorted out.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Cannot get pages in category’ is closed to new replies.