I have to add the custom Post id for the custom post type. can anyone help me?
Check screen short for more details. http://prntscr.com/mo3eyu
This is a work around that works.
Background info:
We maintain a few almost identical web pages with different branding. The code repo is shared across these. The developers hard coded page IDs into the PHP in the past. I was asked to add new pages. After adding new pages on each website, I noticed the IDs were all randomly generated. This was breaking PHP code's logic. So, I needed to edit these IDs just like OP.
The work around:
In WP web admin page, there's an export / import functionality under tools menu. The new pages should be created in one site, then exported / imported onto other websites. This way, page IDs don't get created randomly. It copies the IDs from the exported page. So you can have same IDs on all pages.
PS:
Not sure why the past developers decided to hard-code page IDs in the code. This shouldn't have been the case to start with. When you don't have much time to refactor everything, stack overflow always comes to help.
IDs determine post record storage in database, changing them directly would be highly prone to breaking things. For example extensions often store IDs as a way to refer to specific post and do something with it.
The simple way to change to some ID would be to just create a new post and copy data over (through admin or with code either).
Post ID of a post also reflect in tables other than Post table, like post comments table. Changing post ID will disturb the relationship of post table with other tables, so it is not advisable.
Related
I've been thinking about this for weeks now and can't seem to get a possible solution on how to implement a publishing feature? like in a wordpress page you need to publish the page so the changes will be reflected in the live website? How do you normally do this kind of functionality? I'm just confused because if I change the data in the database then it will affect the live site even though i'm still editing the page. Any tutorial or resources would be very dope. Thank you guys, Have a great day.
I don't have any tutorials or resources to give, but my advice is separating types of content you use. For example, when you are editing something, make sure it's type is set to "draft" or something like that. When you publish, just create a copy of draft with a type of "published".
Yes, you will have duplicated data in the database, but when showing content on page, you won't see it.
I am afraid there is no other way to do it, except maybe having one model have additional fields, which are meant for just editing and when published, their values get assigned to the main object variables.
I currently have a MySQL database from my old site that used to have a basic PHP log-in form and it would query a table containing the user information to log them in. Basic stuff. However I've recently moved to WordPress and it appears to be quite overwhelming at first, so I'm struggling to understand how to integrate my old log-in form with a WordPress site.
I have tried looking at this post:
Wordpress login system and I am still confused. I understand the 'loop' is responsible for displaying multiple 'Posts' on a single page. But to integrate my own PHP code or more specifically; a log-in page, would I make a logged-in 'Post' and a not-logged-in 'Post', and perhaps use a template to display one or the other for a single page via a 'Loop' that uses an if statement to check if the user is logged in?
Or is there some easier method that I'm completely missing?
Thanks!
EDIT: I've thought about creating two pages, both using a template to check if the user is logged in at the top, and display relevant content if they are, or redirect to the log-in page if they aren't. Would this work?
The other possible method I could think of is creating two Posts and displaying the relevant one on a single Page via The Loop. Would this be possible? Are there any security concerns?
EDIT2: I'm going to try the Members plugin and see if I can modify the WordPress MySQL tables to allow room for my previous data.
EDIT3: I need to sync my user logins to our external database as it contains flags to check whether my members are able to access our 'support' pages. I'm not sure how this would be viable while relying on the normal WordPress login system and tables.
Keep it simple stupid.
The point of WordPress is to make things easier. So if you want to go with WP, you should adopt the WP way of doing things.
As comments has suggested, import your current user table into WP. Should be simple enough to change the columns around to get a working import directly into the WP users table.
If there is extra information in your current user table, simple create new fields in the User Profile section of WP. There should be plugins for this (although I have not tried any), but it is quite simple to add these fields yourself, just google for it, there are many tutorials.
For a frontend page to be accessed by only logged in users, simple create a page template and check if user is logged in with is_user_logged_in().
For the access part (Support Pages), either create different user roles and check that the currently logged in user is of the correct role. Or you could also add a custom user capability and validate it on your support pages.
Based on the very general details you have given there is no 'easier method' you are missing. We can't help you form the requirements of your application, but we can help with code if you paste examples of the code you are using, what you are trying to achieve, and what is going wrong with it. Pick one thing, try it out, and if it doesn't work and you get stuck then post it here.
I have a website made with WP (a customer passed me). He want to see in one of the pages, a list of product categories, and to get the list of this product categories, I have to send a request to an API in another website. The site will response with an XML that contain the categories. To make the request I will use some PHP library. After the response is arrived, I want to show those categories in the page of my site of my customer.
I have followed the first answer here to call a php file before rendering a template, but imagine that I want to pass a variable (product categories) from the php to to the template. How can I do that?
You will probably want to cache the results of the XML that comes back to you (unless it is truely dynamic), and possibly store it in a table. You can decide how often you need to refresh the cache. (This will protect your site and their API from DOS attacks, or even just high volume).
Once you have your data stored in a table, your template can simply retrieve it.
This pattern will reduce the coupling between the two parts of your solution, and make things a bit easier to build / debug.
What I am trying to do is to make something similar to what I see all the time on almost any website. The button that says Share to facebook. The goal for me is to let my guests share the item they are viewing in my store (Ran on prestashop) on their blog I run (Running on Oxwall).
The goal is for the button to not only link to a blog post submission webpage but to already have the subject line filled out with the item they are sharing's name and the blog post to display the information about the item. I would like to try and do all this using PHP. I am not sure how to go about doing it but I am sure that I could pass the value. Please note that I can mod BOTH the blog site and the shop as I run both and want to connect them.
As an extra bonus I am also running a forum using phpbb3 if I could do the same thing but onto that as well I would greatly thank you. I am trying to interlink everything into one big network. I know its not an easy task but I am sure there is an easy way to pass data onto the other site so that this can be done.
Facebook a 2 tools to get items informations in the page, it parses the page looking for the most common tags and it uses OpenGraph.
You can also provide product informations in the head of your page (between head tags), then blog side, you retrieve only the contents and parse it as XML.
I advise you to cache this data to avoid useless connections between websites and awful overloads while parsing.
You can use your own specifications, Open Graph or another standard, but i advise to use a standard.
I have created a widget for my web application. User's getting code and just pasting that code in their website and my widget works on their website something like twitter, digg and other social widgets.
My widget is on the basis of post, for a single post (say postid: 234) I am providing single widget, so anyone can embed the widget on their website.
Now I want to know that where all my widget is posted and for which post? for that I have recorded the URL of the site when my widget start (onload) but the problem arises when someone placed the widget in their blog or website's common sidebar. I am recording URL each time and hence if it's in sidebar of a blog then it's recording URL for every post which is creating duplicates.
can anyone help on this? How should I go so that I have only one single record for a widget on a site?
I think doing something like this is a bit tricky. Here are some ideas that pop to mind
You could for example ask the user to input their site's URL when they get the widget, or the widget could track the domain or subdomain, thus giving less URLs.
Just tracking the domain would obviously be problematic if the actual site is domain.com/sitename/, and there could be more than one site under the domain. In that case, you could attempt to detect the highest common directory. Something like this:
You have multiple URLs like this: domain.com/site/page1, domain.com/site/page2, and so on. Here the highest common directory would be domain.com/site.
I don't think that will always work correctly or provide completely accurate results. For accuracy, I think the best is to just ask the user for the URL when they download the code for the widget.
Edit: new idea - Just generate a unique ID for each user. This could be accomplished by simply taking the current timestamp or something, and hiding it into the code snippet the user is supposed to copy. This way you can track the ID itself and any URLs and domains it appears in can be grouped under it.
If you have an ID which doesn't get a hit in say week or something you could remove it from your database, and that way avoid filling it up with unused IDs.
I agree with Jani regarding a unique id. When you dish out the script you'll then be able to always relate back to that id. You are still going to have duplicates if the user uses the same id over and over, but at least you'll have a way of differentiating one user from another. Another useful advantage is that you are now able to, as Jani said, group by the ID and get a cumulative number for all of the instances where that user used the script & id.