Bringing the Wordpress Backend posts search to the frontend - wordpress

I work on a shop using WordPress and a discontinued (but still used) shopping plugin/theme.
The frontend search was never very good, even after some alterations to the way the search query is built. A fulltext index did help a bit, but it largely fails now, because there are many (almost) three-letter product names like t-700 / 700.
In the backend products search (must be a custom post type) however, the search is fine. It is just what the shop owner wants.
The perfect thing would be to bring just this backend search to the frontend, either by calling the right function / hook or by copying the relevant code.
The code structure pointed me to wp-includes/query.php, but there I failed to understand how backend queries work. I've been searching the web for days now and I just can't find anything at all.
Any help or suggestions are greatly appreciated. Thanks a lot!

What you are using on frontend ? you must use query_posts for all posts on frontend as it gives option to pass all possible arguments in it.
You can check this link for reference

We need some more informations to help you! Without knowing the plugin you use or at least what's in the query.php it's impossible to help you.
The code for this search tool is specific so nobody can tell you how to get it to work in your frontend.
Usually I'd try to copy it into a frontend page (or try to call it there) but that might be a risk! Backend and frontend data should have different access rights, this might be the reason why you can't just copy&paste the function.

Related

Wordpress - CRUD operation from the front end

I'm in a bit of crux here. I have this application designed that basically allows users to enter info, create an entry, etc. etc. all the usual CRUD operations from the front end only. No user should ever have to mess around with the admin page.
When this was designed, I was thinking of using the standard way of just using JavaScript to grab all the necessary info, put it into a JSON object, and send that back to the SQL database.
However, there are a few issues with this. I'm not sure how to hook up javascript code to a button in wordpress that will fetch the entered info and upload this to wordpress SQL database, and then later retrieve this information.
I've seen lots of plugins, for instance, wpdataaccess, which is create in terms of creating an SQL database and such, but it doesn't really have much functionality for a customizable CRUD front-end. There are shortcodes, which are about the closest that you can come to this.
But ideally I'd like to somehow just have a button with JavaScript code that says like ok grab the info from each of the fields and upload it to the SQL database.
Is this only possible with a custom-coded plugin? Or do plugins for this already exist? Or do I even need a plugin?
Really any help would be appreciated here.
Also, you're probably wondering why I'm using wordpress... I don't really have an option here - I've got a raspberry pi OS that was built on top of WordPress so I sort of have to stick with it.
Thank you so much
I was able to find a solution to this. Use the plugin gravity forms to have users enter their data. Then, you can display the data back with another plugin, gravity view.

How to track "popularity" of a WordPress post (views, shares) to present the "hottest" posts in category?

I can code, but don't know much about WordPress internals, so would appreciate any advice or instructions. I am looking for a solution to present the posts on my site in the order of popularity. I am thinking of the following signals:
- number of views
- number of times a download link inside the post was clicked
- number of likes on FB (currently using Monarch plugin)
Please help me to figure out how to get those inputs recorded with WP. When available a no-code solution like plugin will be more preferred unless it has some considerable issues. Examples or tutorials would also be great.
Thank you
You've got a couple of options, first you could use a plugin which would be the easiest way to solve your issue:
https://wordpress.org/plugins/wordpress-popular-posts/
Or you can take a no-plugin approach and do something similar to this:
http://www.wpbeginner.com/wp-tutorials/how-to-track-popular-posts-by-views-in-wordpress-without-a-plugin/
I'm not sure how you'll go finding a solution that will integrate page views with social sharing, that would require popularity being abstracted from page views themselves and another counter being created and incremented via a callback from your social API's.

How can I pull a Wordpress header and footer into Laravel views?

Before I get to the question, let me say that I saw a similar question here with a fairly detailed response:
https://wordpress.stackexchange.com/questions/115211/loading-wordpress-stuff-on-laravel-site
And it was the closest thing I have found on the web to what I'm looking for, but the potential solution looked like it might end up being so laborious as to not be worth the time. Here is my situation:
I develop and maintain a small custom SaaS program that typically functions on a subdomain of a client site (say, software.client.com). The latest version of the code was rewritten using Laravel and there were a lot of gains associated with that. In the past, when the program was basically procedural spaghetti, if we had a client with a Wordpress site on their primary domain, we ran some atrocious (by best-practices standards) hack-around code to pull the Wordpress header and footer onto the pages of my program - sitting, of course, outside the CMS - while modifying meta tags and doing a number of other things. It wasn't pretty but it worked.
Now I'm in a situation where I'd like to solve the same problem - that is, to at least pull the Wordpress headers and footers onto some of the Laravel subdomain views - but nothing I have found on the web so far has enabled me to make much progress in that direction. I have found a lot of tutorials explaining how to integrate Laravel and Wordpress, or use one for frontend and the other for backend, etc., but nothing yet about the specific type of integration I'm talking about.
What I have tried so far is implementing some of the code I've used elsewhere into various parts of the Laravel codebase. Most of the recent experiments have been in public/index.php and in Controller methods. Laravel will allow me to get as far as including the Wordpress config, but if I attempt to go any further I cause a 500 error. Here's an example snippet that actually attempts to do more than I need, but I can't even get past wp_init(). Imagine the following code in a Laravel Controller method. The first two lines are OK, but:
public function index() {
define('WP_USE_THEMES', false);
require '/path_to/wp-config.php';
$wp->init(); // from here on, 500 errors occur
$wp->parse_request();
$wp->query_posts();
$wp->register_globals();
// And then, at some point, I would call and modify get_header()
(I didn't really expect this to work from the Controller, but it doesn't work from anywhere else in the codebase I've tried either.) This is not a situation where I want to hand off control from Laravel to Wordpress for these URLs (I need Laravel functions / DB queries and more flexibility, and I know I could just do that hand-off through public/index.php and routes.php if it would solve the problem). And for these intallations, I don't need to grab posts or other items from Wordpress. I would just like to find a way to pull the header and footer into these views directly from Wordpress while maintaining control of the views in Laravel. If I can't, among other things, the design team will end up rebuilding headers and footers for every program install on a Wordpress client (for the time being) and they will have to make changes in at least two places when things are modified or updated.
If we have to, we will find a way to live with that until the next program version rollout, but if I can build a solution in what my superiors will deem a reasonable amount of time, we would all be happier. I hope that I have just missed something simple somewhere and I will be embarrassed to find out that I could have solved this in less time than it took to explain the problem. Thank you for any and all helpful responses and potential solutions.
You're not going to be able to cleanly merge the two codebases together. That would cause a disaster.
The complexity of the solution depends on the complexity the information you need to share. The simplest solution possible would be to write something custom to WordPress that builds a document with no body data and just supplies a token, like {!! $body !!}. Then, in Laravel, you can do an HTTP request to localhost to fetch this tokenized content. Store the result in a memory cache and use Blade to render the final view.
Essentially, my suggestion boils down to: Create a Blade layout with WordPress.
There's a thousand different ways to do this, and all of them are wrong.

Adding a blog functionality to your website without the use of databases? HTML5/CSS

So I have a local website that I am developing and I was wondering if there is a way to create a blog functionality without creating a database and by using HTML5/CSS alone.
From searches around it doesnt seem possible, so maybe if I could embed the blog functionality from somewhere? i.e a blogging service that would allow my users to use my website but they are posting to a database somewhere else?
If I could do that, could you give me an example and what would be the method on doing it?
Thnanks
I actually haven't tried this yet, but you could have a look at http://developer.wordpress.com/, particularly in the API section. For example, if you look at the GET /sites/$site/posts/ API, the doc summary says:
Get a list of matching posts.
So one may use a query matching the pattern:
https://public-api.wordpress.com/rest/v1.1/sites/en.blog.wordpress.com/posts/?number=2
To obtain, in response, quoting the doc page, three parameters:
found (int), the total number of posts found that match the request
posts (array), an array of post objects.
meta (object), meta data
So you may create a free and simple blog on wordpress.com and access its post via the above mentioned APIs. Therefore, you won't require any database on your local site.
Still, some simple PHP, or maybe Javascript is required, but I really can't imagine how one could avoid preprocessing in any non static website, as a blog is. For example, you may use simple GET requests to use the APIs (see this doc as an example of how to do it).

Post rating system on Wordpress Heroku blog

I am trying to install on my blog a system that allow post rating and add in the sidebar the top ten of most rated post...
For this i am trying to use much cummon plugins, such as:
contestant-rating, post-ratings, buddypress-rate-forum-posts, rate-my-whatever
also this:
http://wordpress.org/extend/plugins/wp-postratings/
that looks to be better of all...
But nothing they won't work correctly...it seems to have problem with PostgresSQL DB...
Do you know this issue? if yes, have a solution?
Wordpress is done for the MySQL initially. There's an extension for using PostgreSQL with it, and it even works (we're using it for small blog).
Unfortunately, many plugins are designed to query database directly, not via the Wordpress layer. If this is the case, then you have either to modify such plugin, or look for something else.
There're some movements towards support of more databases, but it is work in progress.

Resources