0

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>
8
  • can you tell us what the actual code output is?
    – rudtek
    Commented Feb 12, 2018 at 15:47
  • @rudtek I don't understand what you asking for, this is my actual code
    – efirvida
    Commented Feb 12, 2018 at 15:57
  • i see the code (but I don't know if you're in a loop as you've only given part of the code) but what I'm looking for is the output. What is the link that results when you run the code. ie what do you see on the frontend? what is the actual link?
    – rudtek
    Commented Feb 12, 2018 at 16:00
  • @rudtek, its inside a loop I update th question with the loop
    – efirvida
    Commented Feb 12, 2018 at 16:23
  • What is the purpose of consulta= in the URL? That's what's causing the 404. You are querying for a consulta post with slug that matches a post's ID, which I'm guessing is not what you are expecting.
    – Milo
    Commented Feb 12, 2018 at 16:56

1 Answer 1

0

How about this:

<a href="<?php echo get_post_type_archive_link( 'consulta' ).'?consulta='.$consult->ID.'#form'; ?>"
1
  • same result, thinks that its no problem with the url, maybe something whith the permalinks
    – efirvida
    Commented Feb 12, 2018 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.