Skip to content
Advertisement

WordPress hide post from custom post-type on a single page

Initial situation

  • custom post-type (projects)[projects.php]
JavaScript
  • custom field (with cmb2)[projects.php]
JavaScript
  • front-page.php
JavaScript

What I want

On my front-page is a section ( <div class="m-rowteaser m-rowteaser--default"> ) what is displaying a random post from the post-type projects.

There are some post that I don’t want to see at the front-page.

Note: the post must be active because there is another page with these post.

In my backend I have a custom field where I want to select if it is displayed at the front page.

The way you can help me

  • give me an idea how a solution could be
  • give me an documentation about it
  • give me a code snippet
  • if you need something from me to help me leave a comment there.
  • please don’t hate me if I have some problems… I work for a short time now with code….

Thank you for helping me!!!! :))))

Update

Now I have a function that can hide post from the front-page by the id. I need help to connect this code with the custom field in the backend.

JavaScript

Advertisement

Answer

You can use the meta_query field to only show projects where _projects_show is set to yes (assuming that’s the field you want to use, feel free to adjust the code below where needed):

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement