Support » Plugins » Hacks » WP_LIST_PAGE exclude pages with custom fields

  • Hello,

    I’m not good in coding and I did not find a easy solution for my need:

    I have a woocoomerce site for which I want to setup a blog as well now. In my themes folder I found this file: template-archives.php with the following code which I had to modify to not list certain pages with those IDs found behind the “exclude” parameter:

    echo avia_advanced_hr(false);
    echo "<div class='one_third first archive_list'>";
    echo "<h3>" . __('Available Pages','avia_framework') . "</h3>";
    echo "<ul>";
    wp_list_pages('title_li=&depth=-1&exclude=9,10,11,12,13,14,15,16,17,943,966,2350,2668' );
    echo "</ul>";
    echo "</div>";

    As this will become impractical soon or later, I’m thinking about a plugin-free solution with a filter in functions.php or something similar. I want to ad a custom field like key=AvoidPageList value=true/false which can be assigned in the custom field section while editing a page. And the filter (or some function) should exclude those from wp_list_pages function.

    Any Idea how to accomlish this?

    btw. the reason why I want this is, that some pages like the start page will change often or are avaiable in different version for content experiments. Also some woocommerce pages like the checkout page or thank you page are retrieved by wp_list_page function which should not be there as they often contain google goal tracking etc.

    Thanks for hints or codes

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    You can do what you want by setting a ‘meta_query’ query var in a ‘pre_get_posts’ action hook, but that may not be the best solution.

    I would create a custom post type for your blog entries, since woo has more or less taken over the normal WP post types. It does take some coding, but the process is fairly well documented, there’s no tricky logic. You will need to place the code in a child theme or your own simple plugin, doing either is quite easy as coding tasks go.

    You new post type will show up in the admin menu as a separate entity, just like posts and pages do already. You select “Create New” and start blogging.

Viewing 1 replies (of 1 total)
  • The topic ‘WP_LIST_PAGE exclude pages with custom fields’ is closed to new replies.