I have a link with alpinejs @click event
<a class="parent post_no" data-value="<?php echo $total_posts_parent ?>" @click="filterPosts(<?= $category->term_id; ?>)"><?= esc_html( $category->name); echo " ". "(" .$total_posts_parent . ")" ?></a>
how can I add the Var $total_posts_parent to the @click and have it received in my alpine function?
Function
Want the on @click $total_posts_parent to populate total
Alpine.data("filterPosts", (adminURL) => ({
posts: "",
limit: 6,
category: 0,
post_type_js: post_id,
showDefault: true,
showFiltered: false,
offset: 0,
total: 0, // want to get the value from the varible here
With
$el.dataset.valueyou can access to the data-value value of the current element, you can use it in the @click event or directly in the filterPosts() method:or:
or: