Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda