ingridskard
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Global variable reset in functions.phpThank you so much for the info and tips! Surprising to hear
functions.php
is initialized anew on each AJAX call, if I’m understanding you correctly.I’m thinking to make a custom plugin to store the global in, if I can’t put it in a session var as the ideal solution would have one global per session. Thanks again!
The blue bar is the tab header.
Forum: Plugins
In reply to: [Insert Pages] Passing variable from template to functions.phpA global variable did the trick. Ugly as sin but works!
Forum: Plugins
In reply to: [Insert Pages] ACF Google Maps plugin and custom templateThanks for the addition! That did away with two warnings on debug too.
Forum: Plugins
In reply to: [Insert Pages] ACF Google Maps plugin and custom templateUpdate: It works! Here’s my setup, for anyone else who might want to display a Google Maps field in from ACF frontend using Insert Pages w/custom template.
Documentation from ACF, https://www.advancedcustomfields.com/resources/google-map/
- Added plugin to new file
google-maps-helper.js
like this:
(function( $ ) { //... })(jQuery);
- Added API key + filter to theme’s
functions.php
and registered scripts,
<?php $api_key = '*key*'; function google_map_api( $api ){ $api['key'] = $api_key; return $api; } add_filter('acf/fields/google_map/api', 'google_map_api'); wp_enqueue_script('google-maps', 'https://maps.googleapis.com/maps/api/js?key='.$api_key.'&callback=Function.prototype'); wp_enqueue_script('google-maps-viewer-helper-script', get_stylesheet_directory_uri() . '/js/google-maps-helper.js', array('jquery'));
Note to make sure to get your child theme’s root directory using
get_stylesheet_directory_uri()
asget_template_directory()
only ever gets parent theme directory.- Added styles to your theme’s custom CSS
- Added viewer code from ACF docs to custom template
Gives us a clean custom template using safely loaded scripts.
Forum: Plugins
In reply to: [Insert Pages] ACF Google Maps plugin and custom templateUpdate: get_field() was missing postId, it now returns ‘location’.
Custom template can render the HTML now, but the map is not loaded, which means the scripts are not found.
Not sure how to add the script to the custom template itself, or if that is good practice?
Edit: https://tmp2.shinysticker.io/loger/loge-parsifal/
- This reply was modified 1 year, 10 months ago by ingridskard.
Forum: Plugins
In reply to: [Insert Pages] Custom templating with full-site editor themes?Fantastic, thank you so much. That did the trick. Turns out my CPT is always at the end of the stack, which lets the template access and output it correctly in any context ??
- This reply was modified 1 year, 10 months ago by ingridskard.
Forum: Plugins
In reply to: [Insert Pages] Custom templating with full-site editor themes?Tested some more and it turns out the template outputs page-ID on tabbed page, sub-page ID on sub-page and CPT ID on the CPT page.
Forum: Plugins
In reply to: [Insert Pages] Custom templating with full-site editor themes?Tried echoing $post->ID and it outputs the ID of sub-page, not the CPT, which explains why it doesn’t target anything.
How can I make the template detect the CPT so I can send in the correct ID?
Forum: Plugins
In reply to: [Insert Pages] Custom templating with full-site editor themes?Hi, thanks for getting back to me so quick and for your suggestion! It works – the plugin finds the template now, and the template can fetch all kinds of fields from ACF using
get_field
, exactly as needed.However as it turns out,
get_field
only works if I send in post id, which completely defeats the purpose of templating… And it is not needed in the tutorial example code.Code below is our currently working template. Ie. if I remove the id argument (1025) it outputs “Emblem is empty!”
Can you see any obvious cause for this behavior? The current context is we’re now templating a page-inserted CPT into a sub-page which is page-inserted into those tabs.
Can we pull id from context somehow, or is there some implicit context that is confused by our setup?
Thanks for taking a look!
<?php /** * Template Name: Lodge Template * Template Post Type: lodge * * Template for displaying ACF for a lodge. * * @package understrap */ // Exit if accessed directly. defined( 'ABSPATH' ) || exit; ?> <article <?php post_class(); ?> id="post-<?php the_ID(); ?>"> <div class="entry-content lodge-content"> <div> <?php $emblem = get_field('emblem', 1025); ?> <?php if ( empty ( $emblem ) ): ?> Emblem is empty! <?php else: ?> Emblem: <img src="<?php echo $emblem['url']; ?>" alt="<?php echo $emblem['alt']; ?>" /> <?php endif; ?> </div> <!-- .image --> </div><!-- .entry-content.lodge-content --> </article><!-- #post-## -->
Aw man it works TYSM ??
Tested and works with post type (all) as well.
Hey, thanks for getting back.
I have logged-in users who need to read posts and pages in my front-end. They log in, but they don’t access admin. So this issue about post visibility/read access, not create/edit/list access.
My users are members of different lodges, where lodge admins can create/publish private or public posts. These posts will be associated with a category representing their lodge on create.
I want non-admin lodge members to be able to see private posts from lodges they are a member of but only public posts from all other lodges.
Public posts are visible to all logged-in members by default, so I’m all good there. It is only granting access to private posts via Groups that is not working.
On top of that I can’t edit the permissions after I store them, which may be an indication that the configuration is not reasonable. GUI gives the impression it is reasonable/possible which is why I thought it could be a bug.
Do you know how to achieve this, please advise. I’m happy to get the paid plugin, just need to know I’ll be able to use this plugin to achieve this specific visibility control.
Hey, thank you so much. That task covers exactly both issues I’m having. I’ll keep an eye on it, thanks again.
- Added plugin to new file