• Resolved smoulden

    (@smoulden)


    I’m trying to make a list of pages by category. I downloaded your plugin, assigned pages to a category and added the following to my template:

    <ul><?php
    	$wedding_links = get_posts(array(
    		'category'		=> 'our-wedding',
    		'post_type'	=> 'page',
    		'post_status'	=> 'publish',
    		'orderby'		=> 'menu_order'
    	));
    	foreach($wedding_links as $link){
    		echo '<li><a href="'.get_page_link($link->ID).'">'.$link->post_title.'</a></li>';
    	}
    ?></ul>

    Instead of posting the 4 pages I want, it lists 5 random pages. Am I not suppose to get_posts? get_pages and wp_list_pages didn’t work either.

    https://www.ads-software.com/plugins/post-tags-and-categories-for-pages/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author curtismchale

    (@curtismchale)

    That should work as long as you have the our-wedding category assigned to pages.

    Have you tried using the tax_query way to get items with get_posts?

    Thread Starter smoulden

    (@smoulden)

    Using tax_query didn’t change anything. What did help though was replacing the category slug with the id. So this worked:

    <ul><?php
    	$wedding_links = get_posts(array(
    		'category'		=> 3,
    		'post_type'	=> 'page',
    		'post_status'	=> 'publish',
    		'orderby'		=> 'menu_order'
    	));
    	foreach($wedding_links as $link){
    		echo '<li><a>ID).'">'.$link->post_title.'</a></li>';
    	}
    ?></ul>

    Plugin Author curtismchale

    (@curtismchale)

    Glad it’s sorted. I wonder if the get_posts documentation is out of date actually. get_posts calls WP_Query and the WP_Query docs don’t include the category parameter.

    It has cat which takes the taxonomy id.

    Is there still an issue that I could be testing for?

    I’m trying something similar, but both pages and posts are being output for the category. I only want the pages to show.

    The ‘post-type’ => ‘page’ seems to be getting ignored.

    Any ideas?

    <?php
      $page_links = get_posts(array(
        'category_name' => 'corporate',
        'post_type' => 'page',
        'post_status' => 'publish',
        'orderby' => 'menu_order'
      ));
    
      foreach($page_links as $link){
        echo '<li><a href="'.get_page_link($link->ID).'">'.$link->post_title.'</a></li>';
      }
    Plugin Author curtismchale

    (@curtismchale)

    You’ll need to look at the pre_get_posts action and change what the main WP_Query object is doing on a category.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Get Pages by Category’ is closed to new replies.