Adding wordpress post ID's to a persistant collection - php

I am using wordpress posts with multiple custom meta to display may items. The items are searched for and added to a collection (or cart) This resembles a commerce solution which are widely used in wordpress I don't understand where they store the variables while the user continues to shop.
To expand further the user will search for items when they see the item they want they can click on it to open a detail view in a modal. Add some specific information (meta) to the item and then ADD to collection. They will then search again for more items and perform the same - all the time building their collection.
Once they are happy with the collection they have created they move to the publish page where I need to output the contents of the collection into a template of the users choice.
The main problems I am facing is being able to add the post ID's and modified meta to local storage / DOM / $_COOKIE etc, some advice on the best solution would be great.
I have searched high and low and I cannot find anything that does this without getting bogged down in useless ecommerce features.
Many thanks

The easiest way to do this is probably to set cookies. The fantastic jQuery.cookie plugin found here makes this a piece of cake - setting and retrieving cookies just takes one line of code:
To set:
$.cookie('cookiename', 'cookievalue');
To retrieve:
var whatever = $.cookie('cookiename'); // assigns 'cookievalue' to var whatever
You can also set them to expire after a set amount of time, etc (those are session cookies above). If you need to store arrays (e.g. of post IDs or meta values) the plugin also lets you store JSON objects as cookies. See the documentation on the page I linked for details.

Related

Seeding wordpress custom post with sample data

I am building a wordpress site for a client. The concept they want to use is having a restaurant-menu be used as a boilerplate, but making fields like price and/or food items adjustable on a per location basis.
The approach I would like to use is:
Use custom post types
Use advanced custom fields
Pre populate the custom post type with sample data that will automatically be reproduced every time I create a new post
With 3. I am hitting a roadblock. I am looking for either a simple , plugin based way to achieve this or a PHP driven db insertion function. Doesn't matter to me, whatever works. Any resources would help!
Thanks
On this post the approach suggests using the wp_insert_post_data function
if (isAdmin()){
add_filter('wp_insert_post_data','custom_insert_post', '99', 2);
function custom_insert_post($data, $postarr){ <--
$data['post_title'] = 'default_post_title';
$data['post_status'] = 'future';
//.... etc
}}
I worry about the limitations of hard coding the database insertion if the ACF keys are changed in a future iteration, affecting the seeding method I've created initially. So I'm wondering if there is a plugin that allows me to pre-populate a given post type (id, key, ...etc), or a post in stack overflow that has solved a similar problem. Ideally, I'd like to have a given post generated in a GUI and then have that first insertion prepopulated in subsequent posts.
Desired output in wordpress back end

In my Wordpress plugin, how do I save and retrieve Multiple indexed sets of data with the Settings API?

I need my plugin to save and edit multiple indexed sets of key/value pairs on my custom settings page and retrieve later them by their index on the Appearance>>Widgets page.
Is it best to create a custom table in the database for this or does the Settings API have two dimensional accommodation for this?
I found that the short answer was to go ahead and expand the existing wordpress database. That is because the Settings API really only goes one dimensional and would be a very inefficient use of the database. https://pippinsplugins.com/custom-database-api-reasons-for-custom-tables-and-an-api/
EDIT: Pippin no longer offers this without a paid membership, but an older version is still available via the internet archive: http://web.archive.org/web/20160611220718/https://pippinsplugins.com/custom-database-api-reasons-for-custom-tables-and-an-api/ If Pippin helps you, I encourage you to try his membership. It has tons of useful wordpress goodies.

populate Wordpress page/post from external db - on the fly

After providing an event calender with PHP/MySQL/HTML/CSS I want to use Wordpress for that project from now on. Account and data management will remain outside of wordpress scope.
My best idea so far is to populate the posts (or pages) entirely from the already existing db. The URLs would be created by apache's rewrite engine.
To use one post and populate just the content would lead to really bad SEO.
So I want to create (virtually) unique posts populated entirely from the db. Extensive research on that topic brought up nothing usable so far. Maybe someone could point me in the right direction?
Preferences:
using mod rewrite to create the pages urls from event /ID/title rather than using the timestamps to create posts
keeping the data editable via external admin panel (no copying into WP-DB)
head data of post / page must be populated from db, e.g. title, author, timestamp etc.
Suggestions would be much appreciated, thanks in advance.
Have you tried the plugin WP All import. It creates unique post such are car listing etc based on the external DB. I also allows you to style and format your post.
https://wordpress.org/plugins/wp-all-import/

Wordpress Plugin - Saving simple data about a post

I'm trying to create a plugin in wordpress that allows you to age restrict certain posts and pages but not others. I looked for a plugin that does this and couldn't find one. I've got all the coding covered except I can't figure out how to instruct wordpress to save the state of the checkbox as data associated with that post or page. I dissected a couple of plugins that have similar functionality but am mystified by how their code works and it breaks when I try to modify it for my use.
Can someone point me to a tutorial that explains how data gets saved from the post edit page and how to access that data later?
check out post meta-data :
http://codex.wordpress.org/Custom_Fields
The basic idea is WP allows you to add additional fields to a post, and then retrieve it during the loop. Just use this field to test against at render-time and display alternate content, should (in this case) your post be restricted.
The codex is pretty thorough on the subject, and I'm sure google can fill in the gaps -
Hope that helps

Modx custom tv with multiple inputs

I need to build a custom tv in modx that will all a user to select a image, a title and a date.
Can't seem to find any help other than the docs with although detailed don't answer my problem.
Anyone done this before and are able to advise me further
Cheers
I'm not 100% sure, if this is what you're trying to archieve, but I think multiItemsGridTv (MIGX) for modX revolution is what you want.
From the docs:
MIGX (multiItemsGridTv for modx) is a custom-tv-input-type for adding
multiple items into one TV-value and a snippet for listing this items
on your frontend.
It has a configurable grid and a configurable tabbed
editor-window to add and edit items. Each item can have multiple
fields.
For each field you can use another tv-input-type.
Essentially, you can make up a set of multiple different template variables (including images), that always belong together. If you then assign your MIGX tv to a template, you can enter as much of these sets as needed per resource.
You can download it via package management or from the modX Extras Repository.

Categories