Ok I’m setting my own function inside the variables, should work
And no, because is an array :/
To replace the use of get_the_title() with the conditional that you provided, you can try the following approach:
- Replace
get_the_title() with get_the_title(get_the_ID()). This will allow you to pass the post ID as an argument to get_the_title() so that you can get the title of the current post in the loop.
- Replace
var_dump($loop) with the following block of code:
if($modo_vista_proyecto == "cuadricula") { ?>
<h2><?php echo get_the_title(get_the_ID()); ?></h2>
<?php echo the_content();
}
if ($modo_vista_proyecto == "tabla") { ?>
<h2><?php echo get_the_title(get_the_ID()); ?> oook</h2>
<?php }
This should output the title and content of the current post in the loop, depending on the value of $modo_vista_proyecto.
It’s also worth noting that the var_dump() function is used for debugging purposes and is not typically used in production code. Instead of using var_dump(), you may want to consider using a more appropriate function to output the data, such as echo or print_r().
if($modo_vista_proyecto == "cuadricula") { ?>
<h2><?php echo get_the_title(get_the_ID()); ?></h2>
<?php echo the_content();
}
if ($modo_vista_proyecto == "tabla") { ?>
<h2><?php echo get_the_title(get_the_ID()); ?> oook</h2>
<?php }
Mmm shouldn’t the $loop variable be passed here? otherwise it would repeat the same title over and over… thank you.
I think you’re right, try this:
if($modo_vista_proyecto == "cuadricula") { ?>
<h2><?php echo get_the_title($loop); ?></h2>
<?php echo the_content();
}
if ($modo_vista_proyecto == "tabla") { ?>
<h2><?php echo get_the_title($loop); ?> oook</h2>
<?php }
Tried
<h2><?php echo get_the_title($loop); ?></h2>
and for some reason it displays nothing, but if I use instead
<h2><?php echo the_title($loop); ?></h2>
it does display each title but at the end of each title it appends the name of the first title like this:
%name_title1% %name_title1%
%name_title2% %name_title1%
%name_title3% %name_title1%
I also wonder with this way how can I pass the ID to the_content or other custom fields?
Oh and have a very happy new year!!!
-
This reply was modified 3 years, 5 months ago by
snippet24.
-
This reply was modified 3 years, 5 months ago by
snippet24.
-
This reply was modified 3 years, 5 months ago by
snippet24.
Okey this is how is done to custom fields:
<?php the_field('field_name', $mypostid) ;?>
But why this is not working properly? (help please here)
<h2><?php echo the_title($loop); ?></h2>
And for the_content seem to be like this:
echo get_post_field('post_content', $post_id);
Ok figured out, here was the issue : (notice should be get_the_ID) :
$loop_destacados[] = get_the_ID();
}else{ $loop_normales[] = get_the_ID();
and used as well
echo get_post_field('post_title', $loop)
Thanks @miketopher for all the help!! π