I need to make a link between to pages, (HOME-> CustomPost Archive) where in the second page esist a form, so I want to go directly to the form. so i made somethink like this:
<a href="<?php echo get_post_type_archive_link( 'consulta' ) ?>#form">
<?php echo $consult->post_title ?>
</a>
and all its fine.
But now I need to send the id of the selected post to the form, with a url param, like this:
<a href="<?php echo get_post_type_archive_link( 'consulta' ) ?>?consulta=<?php echo $consult->ID ?>#form">
<?php echo $consult->post_title ?>
</a>
but this, result on 404 error.
also if I change the order of the params in the url like this:
<a href="<?php echo get_post_type_archive_link( 'consulta' ) ?>#form?consulta=<?php echo $consult->ID ?>">
<?php echo $consult->post_title ?>
</a>
the Id, is working OK, but not the anchor link.
Any idea on how to solve this?
UPDATE the loop
<?php
$args = array(
'post_type' => 'consulta',
);
$consults = get_posts( $args );
?>
<div class="consultation-items">
<?php foreach ( $consults as $consult ):
$category = wp_get_object_terms( $consult->ID, 'consult_category' );
$thumb = get_the_post_thumbnail_url( $consult ) ?>
<div class="grid-item-row">
<div class="grid-item">
<div class="image"><a href="<?php echo get_post_type_archive_link( 'consulta' ) ?>#consulta-form?consulta=<?php echo $consult->ID ?>"><img src="<?php echo $thumb ?>"></a></div>
<div class="item-info">
<p><?php echo $category[0]->name ?> </p>
<h4>
<a href="<?php echo get_post_type_archive_link( 'consulta' ) ?>#consulta-form?consulta=<?php echo $consult->ID ?>">
<?php echo $consult->post_title ?>
</a>
</h4>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
consulta=
in the URL? That's what's causing the 404. You are querying for aconsulta
post with slug that matches a post's ID, which I'm guessing is not what you are expecting.