Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

WordPress how to filter what pages to display, if page URL/slug contains -nv/

WordPress how to filter what pages to display, if page URL/slug contains -nv/

now it shows all the pages on the website, the question is how to filter this to show only pages that contain
-nv/
this part URL is unique and matches all the page what i need to display

?><style>
table {
    counter-reset: rowNumber;
}

table tr:not(:first-child) {
    counter-increment: rowNumber;
}

table tr td:first-child::before {
    content: counter(rowNumber);
    min-width: 1em;
    margin-right: 0.5em;
    color: #cfcfcf;
}</style>
    <table>
  <tr>
    <th>id</th>
    <th>title</th>
    <th>url</th>
  </tr>
<?php // Query for listing all pages in the select box loop
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query( array(
'post_type' => 'page',
'posts_per_page' => -1,
 'orderby' => 'title',
 'order'   => 'ASC', // or DESC
));

foreach ($all_wp_pages as $value){
$post = get_page($value);
$title = $post->post_title;
$id = $post->ID;

?> 
  <tr>
  <?php  echo '<td>' . $id. '</td>
    <td>' . $title . '</td>
    <td>';
        global $post;
  if ( $post) { ?>
    <?php echo get_permalink( $id ); ?></td>
  
<?php }
    
}; ?>
</tr>
    </table>

thank you in advance, for being so helpful.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Check if post slug contains -nv using str_contains() function.

Try out this code in foreach loop under $id.

$slug = $post->post_name;

if (!str_contains($slug, '-nv')) {
    continue;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading