0

I'd like to display the content of a custom post type, when hovering over a "question mark icon". In order to get the data, I used the following code (series is the custom post type):

                <?php foreach ($series as $post): ?>
                    <?php setup_postdata($post); ?>
                    <a class="fa fa-question-circle" href="#" data-toggle="tooltip" title=<?php echo get_the_content('post_content', $post->ID); ?>></a>
                    <?php echo the_title(); ?>
                <?php endforeach; ?>
                <?php wp_reset_postdata(); ?>
            <?php endif; ?>

For some reason, it only displays the first word of the post content when I hover over the question mark. When I look at the element information on that page in my browser, it shows me all of the series' content but only the first word is in quotation marks. Here is a screenshot of the element information and as you can see, only the first word "Diese" is in quotation marks: scrrenshot

Am I missing something on how to get the whole content displayed?

1
  • Sonya, note that get_the_content 2nd parameter is not the post->id for a start. See codex.wordpress.org/Function_Reference/get_the_content. Depending whether you want filters applied (shortcodes etc) you could simply do the_content(). You'll also need to strip any html out of the content so you only have plain text, otherwise you'll end up with invalid nested html. This maybe what is causing the problem. Consider just using the excerpt instead.
    – anmari
    Commented Aug 2, 2018 at 11:09

1 Answer 1

0

The problem is that your template doesn't have any quotes around the title attribute at all:

title=<?php echo get_the_content('post_content', $post->ID); ?>

So the browser's making its best guess and using the first word. So you need to add the quotes:

title="<?php echo get_the_content('post_content', $post->ID); ?>"

Also, if you're outputting arbitrary content into an attribute you should use the esc_attr() function to escape the content so that any characters like ", <, or > cannot break the HTML:

title="<?php echo esc_attr( get_the_content('post_content', $post->ID ) ); ?>"
0

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.