Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
How to get the current post type in JavaScript?

I want to change several background colors via "post type". I don't know how to query the "post type". I know, that my code is 100% wrong. I searched the web for a solution. But couldn't find any, that would work.

(function() {
    var elements, posttype;

    function init() {
        elements = document.querySelectorAll('.color');
        posttype = get_post_type();

    }

    function checkColor() {
        if (posttype === 'veranstaltung') {
            element.classList.add('pink');
            element.classList.remove('color');
        } else if (posttype === 'ausstellung') {
            element.classList.add('green');
            element.classList.remove('color')
        } else if (posttype === 'digitale-events') {
            element.classList.add('red');
            element.classList.remove('color')
        }
    }


    init();
    checkColor();


})();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

One method is javascript if you create a function inside function.php which you have to call all the custom post type and return all the post with ajax in javascript which I do not suggest, the second method is to create a custom page and display all the custom post type with php, and then you have to do a condition to check which post type is the post and then add a custom class to each custom post type.*Note: This get all posts of a custom type use:

$posts = get_posts([
  'post_type' => 'custom',
  'post_status' => 'publish',
  'posts_per_page' => -1,
  'order'  => 'ASC'
]);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!