FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
Load post inside div with AJAX in Wordpress
How-ToWeb Development

Load post inside div with AJAX in Wordpress

via Dev.to JavaScriptMathieu Préaud1mo ago

I’m building a website with Wordpress. To resume, I would like to load posts (from my custom post type ‘project’) dynamically with AJAX inside the div .js-panel-content , by clicking a button with the same ID than the post loaded. The issue is, when clicking the button it loads all the posts of my custom post type. I tried to print the ID of the post via AJAX just to see if the ID was loaded correctly. I did it by replacing the line panelContent.innerHTML = data; with panelContent.innerHTML = post_id; The result is, the ID is undefined. The HTML/PHP <?php $args = array( 'post_type' => 'project', 'posts_per_page' => -1, ); $query = new WP_Query( $args ); while( $query->have_posts() ) : $query->the_post(); echo '<button id="post-'. get_the_ID() .'" class="js-btn-load-post">'. get_the_title() .'</button>'; endwhile; ?> <div class="c-panel js-panel" data-ajax-url='<?php echo esc_url( home_url( '/' ) ); ?>wp-admin/admin-ajax.php'> <div class="c-panel__content js-panel-content"> </div> </div

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
25 views

Related Articles

How to Build a Real Multi-Agent Engineering Workflow With oh-my-claudecode
How-To

How to Build a Real Multi-Agent Engineering Workflow With oh-my-claudecode

Medium Programming • 6h ago

Clean Code Principles Every Software Engineer Should Follow
How-To

Clean Code Principles Every Software Engineer Should Follow

Medium Programming • 7h ago

The Real Cost of Abstractions in .NET
How-To

The Real Cost of Abstractions in .NET

Medium Programming • 8h ago

Stop Learning Frameworks — You’re Wasting Your Time
How-To

Stop Learning Frameworks — You’re Wasting Your Time

Medium Programming • 9h ago

How to Self-Host n8n in 2026: VPS vs Managed Hosting (Full Comparison)
How-To

How to Self-Host n8n in 2026: VPS vs Managed Hosting (Full Comparison)

Dev.to • 9h ago

Discover More Articles