Mashup shortcde not limiting no post per page

Home Forums MapPress Support Mashup shortcde not limiting no post per page

Tagged: 

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #18447
    geraldjim
    Participant

    Hi There

    We just created a mashup map where we want to display the location for the current post on the page (ie max 10).  However the shortcode does not seem to work as I am using this

    [mashup width=”100%” height=”400″ zoom=”2″ adaptive=”true” query=”post_type=Events&posts_per_page=10&meta_key=Generic Location”]

    But it is displaying much more than 10 – see page

    https://simpson.smallbizwebsolutions.com.au/alerts/

    any suggestions?

    Gerald

     

     

    #18449
    Chris
    Keymaster

    Hi,

    The mashup will display all the results that match the query, and it ignores the posts_per_page parameter.  If you just want to display locations from the the current page in the blog, this should work instead:

    [mashup query="current"]

     

    #18450
    geraldjim
    Participant

    Hi Chris

    Thanks for the prompt response.

    Try the code you provided but did ot work – I suspect because I am working off a view the was created using “Content Views” plugin where I select all Custom Post ie Events where the custom field Expiry is equal or in the future of the current date.

    Is there a way to do this in the query string?

    #18451
    Chris
    Keymaster

    Hi,

    If you’d like to paste the ‘current’ query into the ‘alerts’ page you listed, I’ll take a look to see if something simple is amiss that is causing the query to be ignored.

    When the mashup query is ‘current’, MapPress displays locations based on the posts in the WordPress global query object ($wp_query).  Normally this is set to the posts you’re currently viewing.

    If the Views plugin isn’t setting that global query properly, it won’t be possible to sync the map with the list of posts.  You might try using the mashup POI list instead, which is always linked to the map.

    #18452
    geraldjim
    Participant

    Thanks Chris

    I’ve duplicated the map so you can see both on the same page and if you need access to the backend please let me know

    Have a great day

     

    Gerald

    #18453
    Chris
    Keymaster

    Hi,

    I don’t see anything wrong with the shortcode, so my guess is the Views plugin is using its own internal query to generate the list.  You can ask the Views developer if there’s a way to set the global $wp_query, which would make that query data available to MapPress and other plugins.

    Alternatively, you can use the map POI list.  That brings us to your original question about how to specify ‘today or later’ in the query string.  WordPress supports date queries using a date_query array (see here for details).  For example, to show everything since yesterday the query would be:

    query="date_query[0][after]=now-1day"

    Unfortunately, WordPress strips out braces inside shortcodes, so the above won’t work in the [mashup] shortcode.  A workaround is to use the HTML codes %5b and %5d instead of brackets:

    [mashup query="date_query%5b0%5d%5bafter%5d=now-1day"]

    That’s hard to read, and I often get questions about this, so I’ve added a patch to MapPress to allow curly braces instead (if you’d like to try the patch, please send a login and I’ll install it for you to test).  With the patch installed, the shortcode would be:

    [mashup query="date_query{0}{after}=now-1day"]

    Also – if you search for posts with future dates, I think WordPress will only show private posts owned by the current user.  So you may need to add the ‘future’ status to the query:

    [mashup query="post_status=publish,future&date_query{0}{after}=now-1day"]

     

    #18459
    geraldjim
    Participant

    Hi Chris,

    The guys at content views were not able to help very much.  Here is their reply

    # modify global $wp_query
    I checked with our team and found that is not possible to modify global $wp_query from our plugin.
    So that is not the solution we can help you.
    
    # any other solutions?
    According to your information, MapPress Pro is showing articles from a list.
    How was the list generated?
    I suspect that you are using a shortcode of MapPress Pro. Am I correct?
    If so, that list is generated by MapPress Pro, so it is duty of MapPress Pro developer to update code to hide the expired events.
    If he wants to get the list queried by Content Views Pro, he can use this PHP variable $GLOBALS[ 'cv_posts' ].

    I looked at the documentation that you provided and if I had to re-create the qp-query the following would be required – sample from the WordPres doco

    Display posts where the custom field key is a set date and the custom
     field value is now. Displays only posts which date has not passed.

    <div>
    <div id=”highlighter_690213″ class=”syntaxhighlighter php”>
    <table style=”height: 350px;” border=”0″ width=”522″ cellspacing=”0″ cellpadding=”0″>
    <tbody>
    <tr>
    <td class=”gutter”>
    <pre class=”line number1 index0 alt2″>1

    2

    3

    4

    5

    6

    7
    </td>
    <td class=”code”>
    <div class=”container”>
    <pre class=”line number1 index0 alt2″><code class=”php variable”>$args <code class=”php plain”>= <code class=”php keyword”>array<code class=”php plain”>(

    <code class=”php spaces”>    <code class=”php string”>’post_type’    <code class=”php plain”>=> <code class=”php string”>’Event’<code class=”php plain”>,

    <code class=”php spaces”>    <code class=”php string”>’meta_key’     <code class=”php plain”>=> <code class=”php string”>’Expires’<code class=”php plain”>,

    <code class=”php spaces”>    <code class=”php string”>’meta_value’   <code class=”php plain”>=> <code class=”php functions”>date<code class=”php plain”>( <code class=”php string”>”Ymd” <code class=”php plain”>),

    <code class=”php spaces”>    <code class=”php string”>’meta_compare’ <code class=”php plain”>=> <code class=”php string”>’>’<code class=”php plain”>,

    <code class=”php plain”>);

    <code class=”php variable”>$query <code class=”php plain”>= <code class=”php keyword”>new <code class=”php plain”>WP_Query( <code class=”php variable”>$args <code class=”php plain”>);
    </div></td>
    </tr>
    </tbody>
    </table>
    </div>
    </div>
    So if we had to re-create the wp-query how would we apply this?

    Hope this helps

    #18460
    geraldjim
    Participant

    The copy and pate failed badly – sorry

    Here it is again

     

    Display posts where the custom field key is a set date and the custom field value is now. Displays only posts which date has not passed.

    $args = array(
    ‘post_type’ => ‘Event’,
    ‘meta_key’ => ‘Expires’,
    ‘meta_value’ => date( “Ymd” ), // change to how “event date” is stored
    ‘meta_compare’ => ‘>’,
    );
    $query = new WP_Query( $args );

    #18461
    Chris
    Keymaster

    Hi,

    I gave an example earlier using post date, but for a custom field the query would be:

    [mashup query="post_type=Event&meta_key=Expires&meta_value=20200201"]

    However, unlike queries by post_date, WP doesn’t provide any way to pass a dynamic date for the meta_value in the query string.

    One solution is to add some PHP to one of your theme’s template files to generate the map instead:

    <?php 
      $date = date('Ymd');
      $query = "post_type=Event&meta_key=Expires&meta_value=$date";
      echo do_shortcode('[mashup query="' . $query . '"]'); ?>
    ?>
    
    #18462
    geraldjim
    Participant

    Hi Chris

    Firstly, Ive created a login for you on our test site so you can have a look at what I done and you may want to add your patch.

    url: https://simpson.smallbizwebsolutions.com.au

    u: chrismappro

    Send me an email to geraldj@smallbizwebsolutions.com.au so I can send you the password.

    I created a shortcode using the above and none of the points display.  I checked the fields and made an adjustment as the date store in Expires is YYYY-MM-DD to
    <p class=”prettyprint prettyprinted”><span class=”pln”>  $date </span><span class=”pun”>=</span><span class=”pln”> date</span><span class=”pun”>(</span><span class=”str”>’Y-m-d'</span><span class=”pun”>);

    Which still does not work. Not sure what else to check. Below is a screen grab of the fields how they appear on the database.

    </span></p>
    Tried to add <code class=”php string”>meta_compare’ <code class=”php plain”>=> <code class=”php string”>’>’ to the quuery but did not like it,

    Any help will be much appreciated.

     

    #18463
    Chris
    Keymaster

    Hi,

    I started simple with this shortcode, but got no results:

    [mashup query="post_type=Event"]

    The problem is the query needs the post_type slug not it’s name.  From the CPT plugin, we can see the slug for ‘Event’ posts is ‘events’.  So this query works:

    [mashup query="post_type=events"]

    Adding the date and meta_compare also seemed to work:

    [mashup query="post_type=events&meta_key=expires&meta_value=2020-02-04&meta_compare=>"]

    Hopefully the problem was just the slug, and that’s enough to help you get the PHP code working.

    #18464
    geraldjim
    Participant

    Your are champ Chris,

    I did not realized that I need to use the slug name –  thanks all working now.

    Will be definitely be recommending your plugin – your support is just A+++

    Thanks s much

    Gerald

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.