How to get the attribute and attribute values from of shortcode inside it ?
-
Exactly I asked in the question, I need to access the attribute values of shortcode inside it’s expanded code.
For example my shortcode is
echo do_shortcode( sprintf( '[ajax_load_more post_type="practt" button_label="More" orderby="meta_value" meta_key="%s"]', $distDiffList ) );
, now I need to get themeta_key
field’s value inside this shortcode’s exapnsion.Can anyone help out ?
-
Hi @vivekse2m,
You can get the $args in the alm_query_args filter.I’m not sure what you are trying to do, so I hope that helps.
Ok thanks, how can I pass custom (non-preset) arguments and access those arguments inside shortcode expansion ?
Ahh yes. You can follow the sample here.
https://connekthq.com/plugins/ajax-load-more/docs/code-samples/passing-variables/Hi, dcooney, are you online ?
I have another query regarding this same topic, can I ask and expect earliest reply from you ?
Regards,
Vivek ShahPlease check below, it is my custom repeater template that I have set in the site for Load More functionality.
I think you will get idea, what am I trying to do here.
<?php error_reporting(E_ALL & ~E_NOTICE); global $wp_query,$shortcode_tags; //$post = $wp_query->post; if(!$_SESSION['location_near_sort_arr']): $post = get_posts(); $post_id = $post->ID; $postMeta = get_post_meta( $post_id ); $practSpecData = get_post_custom( $post_id ); array_walk($practSpecData, function(&$value, $key) { $value = array_shift( $value ); }); $practSpecData = array_filter($practSpecData, function(&$value, $key) { if (startsWith($key, '_')) unset($key, $value); else return $key; }, ARRAY_FILTER_USE_BOTH); $practSpecData = array_filter($practSpecData, function(&$value, $key) { if (startsWith($key, 'eg_')) unset($key, $value); else return $key; }, ARRAY_FILTER_USE_BOTH); $practAddLocs = unserialize($practSpecData['additional_locations']); $practAddLocsCnt = count($practAddLocs); ?> <div class='location_list providers_list'> <div class="clearfix"> <div class="location_img"> <img src="<?php echo wp_get_attachment_url( $post_id ); ?>" class="img-responsive" /> </div> <div class="location_content"> <div class='location_list_content'> <h3><?php echo $practSpecData['firstname'] . " " . $practSpecData['lastname']; ?>, <?php echo $practSpecData['credential'] ?></h3> <p><?php echo $practSpecData['short_biography'] ?></p> <h5>Locations</h5> <p id="pract<?php echo $post_id; ?>"> <span> <?php echo get_location_name_byid($practSpecData['primary_location']); //if($practAddLocsCnt > 0) echo ','; ?> </span> <?php if(!empty($practSpecData['additional_locations'])): ?> <?php $i = 0; foreach($practAddLocs as $addlocation) { $addlocation = get_location_name_byid( $addlocation ); if( $i < $practAddLocsCnt-1 ): echo "<span class=\"addlocshow\">,{$addlocation}</span>"; else: echo "<span class=\"addlocshow\">{$addlocation}</span>"; endif; } ?> <?php if($practAddLocsCnt > 3): echo '<a class="underline" href="javascript:;">(2 more)</a>'; echo '<a class="underline-less" style="display:none;" href="javascript:;">(2 less)</a>'; endif; ?> <?php endif; ?> <script type="text/javascript"> $(function() { var $divHead = $('p#pract<?php echo $post_id ?>'); $divHead.find('span.addlocshow').slice(-2).hide(); $divHead.find('a.underline').click(function() { $divHead.find('span.addlocshow').slice(-2).show(); $(this).hide(); $divHead.find('a.underline-less').show(); }); $divHead.find('a.underline-less').click(function() { $divHead.find('span.addlocshow').slice(-2).hide(); $(this).hide(); $divHead.find('a.underline').show(); }); }); </script> </p> <a href="<?php echo get_permalink($post_id) ?>" class="learn_more">Full Profile</a> </div> </div> </div> </div> <?php else: ?> <?php foreach($_SESSION['location_near_sort_arr'] as $post_id => $value): $postMeta = get_post_meta( $post_id ); $practSpecData = get_post_custom( $post_id ); array_walk($practSpecData, function(&$value, $key) { $value = array_shift( $value ); }); $practSpecData = array_filter($practSpecData, function(&$value, $key) { if (startsWith($key, '_')) unset($key, $value); else return $key; }, ARRAY_FILTER_USE_BOTH); $practSpecData = array_filter($practSpecData, function(&$value, $key) { if (startsWith($key, 'eg_')) unset($key, $value); else return $key; }, ARRAY_FILTER_USE_BOTH); $practAddLocs = unserialize($practSpecData['additional_locations']); $practAddLocsCnt = count($practAddLocs); ?> <div class='location_list providers_list'> <div class="clearfix"> <div class="location_img"> <img src="<?php echo wp_get_attachment_url( $post_id ); ?>" class="img-responsive" /> </div> <div class="location_content"> <div class='location_list_content'> <h3><?php echo $practSpecData['firstname'] . " " . $practSpecData['lastname']; ?>, <?php echo $practSpecData['credential'] ?></h3> <p><?php echo $practSpecData['short_biography'] ?></p> <h5>Locations</h5> <p id="pract<?php echo $post_id; ?>"> <span> <?php echo get_location_name_byid($practSpecData['primary_location']); //if($practAddLocsCnt > 0) echo ','; ?> </span> <?php if(!empty($practSpecData['additional_locations'])): ?> <?php $i = 0; foreach($practAddLocs as $addlocation) { $addlocation = get_location_name_byid( $addlocation ); if( $i < $practAddLocsCnt-1 ): echo "<span class=\"addlocshow\">,{$addlocation}</span>"; else: echo "<span class=\"addlocshow\">{$addlocation}</span>"; endif; } ?> <?php if($practAddLocsCnt > 3): echo '<a class="underline" href="javascript:;">(2 more)</a>'; echo '<a class="underline-less" style="display:none;" href="javascript:;">(2 less)</a>'; endif; ?> <?php endif; ?> <script type="text/javascript"> $(function() { var $divHead = $('p#pract<?php echo $post_id ?>'); $divHead.find('span.addlocshow').slice(-2).hide(); $divHead.find('a.underline').click(function() { $divHead.find('span.addlocshow').slice(-2).show(); $(this).hide(); $divHead.find('a.underline-less').show(); }); $divHead.find('a.underline-less').click(function() { $divHead.find('span.addlocshow').slice(-2).hide(); $(this).hide(); $divHead.find('a.underline').show(); }); }); </script> </p> <a href="<?php echo get_permalink($post_id) ?>" class="learn_more">Full Profile</a> </div> </div> </div> </div> <?php endforeach; ?> <?php endif; ?>
I am trying to do customized sorting for “near me” locations, and as those type of sorting cannot be done by database, I am taking the help of array sorting, but when I do that I am getting same slot of records over and over again when I click on “More” button.
Can you help out, it’s really urgent….
Regards,
Vivek ShahHi Vivek,
You are likely getting the same records because you are either not offseting the results on each load, or not excluding previous results from being displayed.Would that make sense? You need to exclude previous results by storing them into a global variable or session.
Ok, but can you show me with an example relative to my code I have posted, can you show me a demo for the same ?
Sorry, I don’t have any demos this unfortunately.
- The topic ‘How to get the attribute and attribute values from of shortcode inside it ?’ is closed to new replies.