• Resolved shoxt3r

    (@shoxt3r)


    Hi there,

    I’ve currently got a Custom Post Type of Cinemas which pulls through various Advanced Custom Fields data including a Google Map which shows all of the Cinemas on a map.

    Please could you tell me how I could use the Store Locator plugin alongside ACF to create a filterable Store Locator page? Each Cinema post has latitude and longitude values attached to them.

    Many thanks in advance!

Viewing 15 replies - 1 through 15 (of 20 total)
  • Thread Starter shoxt3r

    (@shoxt3r)

    Hi there,

    Apologies if I didn’t make myself clear in my original post. I’m basically looking to implement what was mentioned in the following post but instead of “schools”, it’s cinemas.

    If anyone could point me in the right direction I’d really appreciate it as this plugin is perfect for my needs otherwise.

    https://wordpress.org/support/topic/custom-post-type-instead-of-stores/

    I’ve currently got a “Cinemas” Custom Post Type with an integration with Advanced Custom Fields so I need to find a way to try to dovetail the two together…if that’s possible?

    Below is a screenshot of the Cinemas CPT I have so far:
    https://pasteboard.co/KefcK2v.png

    Many thanks!

    • This reply was modified 2 years, 8 months ago by shoxt3r.
    Plugin Author Tijmen Smit

    (@tijmensmit)

    If you want to use a different custom post type, then the only way to change this at the moment is to search through the code and replace ‘wpsl_stores’ with whatever you want to use instead.

    You could if you only want to use certain data from the ‘cinemas’ type in the meta data on the front-end with this filter, or use this filter to make it search for the lat / lng fields in custom meta fields.

    Thread Starter shoxt3r

    (@shoxt3r)

    Thank you!
    Do you think it would be possible to combine the two post types (Store & Cinema) or would I be better off creating the Store CPT as a Cinema CPT, and then adding my ACF fields onto that afterwards do you think?

    At the moment I’m going through the code and replacing all mentions of “store” (where relevant) and replacing them with “cinema”.

    Thank you again for your help.

    Thread Starter shoxt3r

    (@shoxt3r)

    Hi again Tijmen,

    I decided to start from scratch with the plugin and replaced “wpsl_stores” with the custom CPT name of “cinema” (I was obviously too half-asleep to work out your original reply – sorry!).

    The problem is that the permalink for the “all stores” page is now using the page template from “index.php”, rather than “archive-cinema.php”. By contrast, each of the individual “cinema” pages are using the correct “single-cinema.php” template.

    As a carryover from before I installed the WP Store Locator plugin I’ve got the following code which rewrites the URL for the “cinema” post type and sets an archive.

        // Cinema Post Type
        register_post_type('cinema', array(
            'show_in_rest' => true,
            'supports' => array('title', 'excerpt'),
            'rewrite' => array('slug' => 'cinemas'),
            'has_archive' => true,
            'public' => true,
            'labels' => array(
                'name' => 'Cinemas',
                'add_new_item' => "Add New Cinema",
                'edit_item' => "Edit Cinema",
                'all_items' => "View All Cinemas",
                'singular_name' => 'Cinema'
            ),
            'menu_icon' => 'dashicons-location-alt'
        ));

    Any thoughts why the “archive-cinema.php” page isn’t being used as a template or is there a conflict? The above code seems necessary, otherwise the page doesn’t show up at all!

    Many thanks

    Plugin Author Tijmen Smit

    (@tijmensmit)

    If you simply re-save the current permalink settings on the Settings -> Permalinks page in the admin area, then that doesn’t save fix it?

    Thread Starter shoxt3r

    (@shoxt3r)

    Yes even then it doesn’t seem to be working. I’ve also tried renaming the “archive-cinema.php” to match the permalink name set in the WP Store Locator settings, or even without the “archive” bit (taking care to save the Settings > Permalinks setting in the admin area each time) but nothing seems to work.

    My only thought is that there’s a conflict somewhere.

    Thread Starter shoxt3r

    (@shoxt3r)

    Please could you tell me what the default “all stores” page template the scripts look for?

    Thread Starter shoxt3r

    (@shoxt3r)

    Ok, so I’ve tried out a few different things and then decided to edit the index.php file as that was the only one that seemed relevant given the content that was showing and lo and behold that’s the template it’s using. I can’t figure out why that is though unless it’s a default for WordPress?

    I’ve since renamed the CPT to “theatre” and updated all plugin code accordingly, just in case it was getting mixed up with my previous CPT of “cinema” and causing a conflict.

    Note that the “single” page template is working fine – therefore “single-theatre.php” is being used as expected. I’m not aware of anywhere in the code where I set the index file as the default page template, nor for the “theatre” CPT. There is a parameter set for the “theatre” CPT which sets up an archive (“has_archive”) – however, setting up a new page with the name “archive-theatre.php” doesn’t change the layout as needed – the “theatre” CPT just continues to use the index.php for layout.

    At every stage I’ve saved the permalinks to ensure any new changes go through as expected but unfortunately it’s still not working.

    Below is the code I have to set parameters for the “theatre” CPT.

        // Theatre Post Type
        register_post_type('theatre', array(
            'show_in_rest' => true,
            'supports' => array('title', 'excerpt'),
            //'rewrite' => array('slug' => 'theatres'),
            'has_archive' => true,
            'public' => true,
            'labels' => array(
                'name' => 'Theatres',
                'add_new_item' => "Add New Theatre",
                'edit_item' => "Edit Theatre",
                'all_items' => "View All Theatres",
                'singular_name' => 'Theatre'
            ),
            'menu_icon' => 'dashicons-location-alt'
        ));

    Let me know if any further details would help.

    Thanks!

    Thread Starter shoxt3r

    (@shoxt3r)

    If it helps, here is the setup I have for WP Store Locator https://pasteboard.co/Kf0hLTO.png

    Thread Starter shoxt3r

    (@shoxt3r)

    Ok I’ve now attempted to create a Parent Page for the “Theatres” CPT using the following code which hasn’t worked, despite resetting the Permalinks from within the WP settings.

    function create_theatre_acf_pages()
    {
    	if (function_exists('acf_add_options_page')) {
    		acf_add_options_sub_page(array(
    			'page_title'      => 'Theatre Parent Page Settings',
    			'parent_slug'     => 'edit.php?post_type=theatre',
    			'capability' => 'manage_options'
    		));
    	}
    }
    add_action('init', 'create_theatre_acf_pages');

    I’ve also created the “Theatre” page within my WordPress setup Pages area and created the corresponding “page-theatre.php” and “archive-theatre.php” but nothing seems to be working, not even if I reset the Permalink settings each time.

    If I can just find out why it’s defaulting to using the “index.php” despite setting a new page up to match as above ,then I’m sure I’d be able to solve it. Is there a default naming convention that WP Store Locator uses for it’s main “All Stores” page? If so, where would I find that setting please?

    If any other details would be help to look into this please let me know as I’m running out of ideas now haha

    Thanks in advance.

    Plugin Author Tijmen Smit

    (@tijmensmit)

    I feel like this can only be fixed by creating custom rewrite rules, but this is something I know very little about.

    If you ask here or here about this, then there will probably be someone who can point you in the direction. I also have no idea at this point how to make this work 🙁

    Thread Starter shoxt3r

    (@shoxt3r)

    Ok no worries, thanks for the suggestions!

    When creating an “All Stores” page to hold the search tool where would this be created – is the intention just to use a standard page and place the shortcode on there?

    If you have a guide in the documentation that would be really helpful but when searching I didn’t find one.

    Thanks again.

    Thread Starter shoxt3r

    (@shoxt3r)

    Ah ok – I just tried disabling the plugin and the “theatre” page now uses the correct template of “archive-theatre.php” but it also reverts the “Store Locator” menu option within the Admin area back to “Theatres” which matches the settings I posted earlier.

    As soon as I activate the plugin again, it changes the menu option in the admin to “Store Locator” and reverts back to using the “index.php” page for the template.

    I suspect therefore there is a conflict or something I’ve missed when changing the “stores” references to “theatres” – any thoughts please? My only option may be to start again with the plugin and keep it as “stores” for now and see how I get on.

    Thread Starter shoxt3r

    (@shoxt3r)

    Ok, so I wrote on the WordPress forums and they came back with the following:

    `I suspect the plugin is forcing a specific template through the “template_include” filter. It’s a common technique, but I’m only speculating as it relates to that specific plugin. If this is indeed what the plugin does, you can override the plugin’s template choice with your own by hooking the same filter, but adding with a larger priority number so your callback’s template selection has the final say.

    Almost all requests go through this filter. Be sure you only alter the template of the specific page you wish to target. The returned value is immediately included by WP, so you should return a complete path to the desired template.

    Your callback isn’t given much context, but the various is_*() functions like is_single() will work. You can examine the query vars used through the global $wp_query object properties. If you are targeting a single page, you can get its ID through get_queried_object_id().`

    I had a search for “template_include” but it isn’t listed in any of the plugin’s files.

    After searching for the term “template” I did come across the following code, however, but I believe this only refers to the following documentation – I’m unsure if it’s even relevant?

    public function show_template_options() {
                
                global $wpsl_settings;
                
    			$dropdown = '<select id="wpsl-store-template" name="wpsl_ux[template_id]" autocomplete="off">';
    
                foreach ( wpsl_get_templates() as $template ) {
                    $template_id = ( isset( $template['id'] ) ) ? $template['id'] : '';
                    
    				$selected = ( $wpsl_settings['template_id'] == $template_id ) ? ' selected="selected"' : '';
    				$dropdown .= "<option value='" . esc_attr( $template_id ) . "' $selected>" . esc_html( $template['name'] ) . "</option>";
                }
    			
    			$dropdown .= '</select>';
    			
    			return $dropdown;            
            }

    https://wpstorelocator.co/document/load-custom-store-locator-template/

    Any thoughts please?

    Thread Starter shoxt3r

    (@shoxt3r)

    I should also point out that I’ve done a fresh install of the plugin and used the following details within the plugin settings:

    Store slug: “shop”
    Category slug: “all-shops”

    I’ve then registered a new CPT using the following:

        register_post_type('wpsl_stores', array(
            'show_in_rest' => true,
            'supports' => array('title', 'excerpt'),
            'rewrite' => array('slug' => 'shop'),
            'has_archive' => true,
            'public' => true,
            'labels' => array(
                'name' => 'Shops',
                'add_new_item' => "Add New Shop",
                'edit_item' => "Edit Shop",
                'all_items' => "View All Shops",
                'singular_name' => 'Shop'
            ),
            'menu_icon' => 'dashicons-location-alt'
        ));
    

    However, it’s still not possible to use a custom page template it seems.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘ACF & Custom Post Type with Store Locator’ is closed to new replies.