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

254
Visualizações
Wordpress how to check if a post is the first post

I am using the get_previous_post() to check if the first custom post type so I can add a condition. It works if it's not equal to 0 (the first post), to make it work I need to parse the output.

The following didn't work, I get the error Argument ($str) must be of type string

$checkFirst = get_previous_post();
<?php !(wp_parse_str(strlen($checkFirst)) == 0) ? 'something' : '';?>

I have also tried :

wp_parse_str(strlen($checkFirst), $output)
<?php !($output[strlen($checkFirst)] == 0) ? 'something' : '';?>
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Why do you think you need to parse it?

According to the get_previous_postDocs, it returns:

  • Null if global $post is not set.
  • Empty string if no corresponding post exists.
  • Post object if the current post is not the first one.

So you could check its value like this:

$checkFirst = get_previous_post();

echo $checkFirst  
               ? 'There is a previous post' 
               : 'No, this is the first post';

You don't need to use strlen or wp_parse_str.

over 4 years ago · Santiago Trujillo 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