Monday, January 9, 2023
HomeWordPress DevelopmentThe way to get an inventory of pages (not posts) with particular...

The way to get an inventory of pages (not posts) with particular tags?


get_pages() is a sound operate, nevertheless it would not have any parameters for getting pages with particular taxonomy phrases assigned.

WP_Query will get posts of any sort (corresponding to Pages) and might question by taxonomy phrases. In the event you do not wish to look by your plugin’s code to seek out out what it calls the Web page Tag taxonomy, in wp-admin, go to Pages > Tags and take a look at the URL. You’ll have one thing like /wp-admin/edit-tags.php?taxonomy=thetaxonomynamethetaxonomyname is what you are on the lookout for. It will likely be post_tag if it is common Core tags however could possibly be one thing totally different relying on the plugin. As soon as you realize for certain what your taxonomy is named, you may plug that into the tax_query portion of WP_Query.

From OP’s remark, the ultimate code is

<?php
$pages = new WP_Query(
    array(
        'showposts' => -1,
        'tag' => 'thetaxonomyname',
        'meta_key' => 'date',
        'orderby' => 'meta_value_num',
        'order' => 'DESC',
        'post_type' => array( 'submit', 'web page' )
        
    )
);
print_r($pages);
?>

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments