Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda