Wordpress WP_QUERY with GET and AJAX - php

Recently I've been developing on a Wordpress theme, where you can filter different products (A post type) based on custom fields (metaboxes).
After a lot of hard work, I finally found a way to do it, by using the "array" from "get" url, check if it's set and if it is, then pass the array into the WP_QUERY.
Hope this image explains it a bit better
I'm doing it with this code: http://pastebin.com/T5ihsCw3
But now I would really like to update the query, every time a checkbox is checked (or unchecked), by using Ajax. I just can't get it to work, because I NEED to use the "GET" from the URL, and I can't find a guide on THAT specific thing.
Any help would be greatly appreciated!
Thanks!
Frederik

See this post. It shall give you an idea on how to solve your problem:
WordPress: How to get metadata of Custom Fields from Custom Taxonomy with using jQuery
You need to create a function that can be queried by Ajax and then every time one of the checkboxes is checked, you just issue an Ajax get request.

Related

How to Store Permalink to Post Authored by User in His Meta Data - WordPress

Here is the situation.
I have a custom post type, let's call it "Listings." I have numerous authors, each of whom has exactly one post of type "Listings." No more, no less.
I want a custom field, let's call it "listing_link", where the link to each author's "Listings" post is stored. I would like this to be generated automatically.
So essentially I need some kind of function that will:
1. Cycle through each author
2. Find all posts of type "Listings" by that author
3. Get the permalink to the first (and only) post of that type by that author
4. Finally save that link in a custom field I've created
I could code bits of this, but I'm really not sure where to start. When/how would this function run? How would it refresh? How do you actually save it to their meta data?
Any help would be appreciated, even if it's not a full script. I really just need to be sent in the right direction! If I can come up with a functioning solution, I will share it with the community!
Do you have to store 'listing-link'? Why not just query "listings" when you need the information?

Wordpress - How to add a button into a Wordpress' post and make it work?

I've just started writing plugins on Wordpress and I'm struggling with adding a small button on every post that helps translate the whole post into another language. I tried to get the post's content, then add a button into it and return. But this certainly seems very bad. Can anybody think of a different way of doing this?
And (say) if I successfully place a button on a post, how can I make it performs its function when users click on it?
Thank you.
Adding a button to every post can be done using the appropriate action: for what you want to do see the *edit_post* action (at http://codex.wordpress.org/Plugin_API/Action_Reference). You should be able to add your button's content to the end of the post. Alternatively you might need to modify the theme to add the buttons (if you don't want to modify the post content).
As far as performing its function, if you're familiar with jQuery you can attach an event listener to the button you insert into the post that performs the actual functionality. You can make an ajax callback to your plugin as described here: http://codex.wordpress.org/AJAX_in_Plugins.

Wordpress- Displaying and layering custom fields/posts

I am somewhat new to both Wordpress and PHP, and I wanted to get advice on the best way to tackle my problem as I have had little luck doing it successfully so far.
There are two jobs I want to handle:
First of all, I want to have a conditional include on my home page that does the following;
Find a custom post type home_content (only ever going to be 1 post, which is ID 76 - if that helps)
Display 3 custom fields from that post... the values for today_on front_widget_a & front_widget_b
(I guess a secondary question would be - can I even pass shortcode through a custom field, because that's what those widgets are being generated from, is shortcode from a plug-in)
That's pretty much it. I've tried various combination of get_posts and get_post_meta without much success. Either I get some syntax errors I can't figure out (and trust me I've combed my code many times for missing semi-colons and the like). That or I get a result that makes no sense.
The second one is a bit more difficult.
Basically trying to turn a part of my Wordpress into a bit of a CMS-style feature. Basically, I have 2 additional custom post types, one called tag_page_layout and one called tag_page_data.
When a Tag in a post is clicked on, I want the Tag page to grab custom field 1 from the tag_page_layout, and then a couple custom fields worth of data from tag_page_data.
I probably wouldn't even need the two post types if I took the time to learn the PHP or HTML code for making tabs, but again, I'm using a plug-in for Wordpress shortcode (which, if you see above - I'm not even sure is going to work right - of course if its not I'm willing to make multiple of these 'layout' posts so each [tab:NAME] shortcode bit is in it's own post-content area.
So... the tag page will basically have a big bit of code that runs before the loop.... it knows its on a tag page so it starts loading Custom Field 1 from the tag_page_layout, which is essentially a bit of code that starts up a Tab-separated data presentation area. Then it's got to take the tag clicked and match it with the same tag ID from custom post type #2 - the tag_page_data group. Then it will grab the first 3 or so fields from that page, swap back to the layout post, throw another custom field from there to start another tab, and so on and so forth, until a [tab:END] and it runs the loop.
I could include all my various attempts and bits of code that never worked or half worked, but I've been around so many circles trying to construct this. Like I said, my coding knowledge is limited but I can usually feel my way around, however these finer points of trying to make Wordpress a little more CMS-like seem to be harder for me to grasp. Any help would be appreciated!
As far as using shortcodes in custom fields go, this should help you out, where XXX is your custom field name.
<?php
$var = apply_filters('the_content', get_post_meta($post->ID, 'XXX', $single = true) );
echo $var;
?>
This apply's the standard filters wordpress automatically runs on regular post content, allowing it to process your custom field and convert the shortcode.

Recommendation for a Pagination procedure AJAX PHP

I am not sure the correct terminology for the process that I am trying to describe. I don't even know which platform is underlying the technique. If you understand my description, please give the link to the site(s) and or the keyword name of the process. I think it is done by AJAX, but I am not certain. I use php as the backend code, I just need to find a way to dynamically display the results. Please give suggestions. I forgot the name of the sites that use this, and my link history expired.
TIA
Description:
The page would have a search form and options. After the user submits, the search is initiated, and the results appear inside the dedicated result area. The page does not refresh, just the info inside the result area.
The display area will show 20 (or whatever) results (lines). There will be next, and previous buttons. If you hit next, the next set of results will display.
I am writing a code that generates 20 results for each display. There is no set number of results, so the results might have a start/first page, but do not have an end page.
Each time the user hits 'next', the program would generate/load new results. It would also store previous results, so that when a user hits 'prev', the previous results can instantly come up.
What techniques/program are theses?
Having recently handled pagination with Code Igniter (php framework), the following links might help you and anyone else out:
http://tympanus.net/jPaginate/
http://codeigniter.com/forums/viewthread/93045/
Usability is important and AJAX pagination introduces some important questions that need addressing regarding pagination, the following article will give some usability guidelines for displaying results in a table:
http://thedesignvanguard.com/crud-r-for-read
Code Igniter Prototype Framework Ajax Pagination:
http://codeigniter.com/wiki/AJAX_Pagination_with_CI_Pagination_Library/
Since we're using jQuery, we chose the following, Codeigniter jQuery framework for AJAX pagination
http://tohin.wordpress.com/2008/08/12/codeigniter-ajax-pagination/
http://tohin.wordpress.com/2008/10/07/codeigniter-ajax-pagination-exampleguideline/
It is not AJAX for sure.
Nobody uses AJAX for the pagination.
And there are about zillion pagination examples over internet
The only thing is never described in articles is how to persist search options for the other pages.
But it's simple enough: http_build_query() can help you
You need to have a GET/POST form submitted via AJAX which contains the fields in the search term and page number.
If you are going to set the page size to 20 results, page_num=4 will show results from 61-80 results.
Usually search results are GET instead of POST (Ex: See Google search results ) along with the page_number as another attribute and value.
#IVAN .. good to know that the library came helpful..
About that searching option; check the recent commit in github
http://github.com/neotohin/CodeIgniter-Ajax-pagination-Library there is an additional parameter added for searching.
I think the simple code in readme is enough for understanding the mechanism.
You could use datatables
https://datatables.net/
https://datatables.net/examples/data_sources/server_side.html
With this plugin using jquery also you could use server sided page request , you just have to handle the plugin post using Ajax.
post automatically sends row , page offset column, search criteria you just have to provide the json encode return
and the plugin automatically has library in featuring pagination, search sort number of rows per page and the table formatting.
Needed are jquery, and the plugin css and js for this to work
let me know if you understood my explanation.
thanks (=

How can I pass variables from a form within the Wordpress platform?

I'm building a website using Wordpress. The WP-Events plugin is being used to display a list of upcoming events. What I need is for people to be able to confirm their attendance at any particular event.
WP-Events is a bit awkward in that it's customised using a template that is only able to be edited with the Wordpress admin. I used this template in combination with the Wordpress 'Loop' to generate a form for each event that could be filled in and submitted. I then was going to use jquery to toggle the display of each form as to not make the page massive. This plan collapsed when I wasn't able to implement any form validation.
What I have now is a list of events on one page, and a confirmation form on another. What I now need is to pull the event name, date and location from the selected event, and pass them across for use in the form. The problem is that wordpress' permalink structure doesn't seem to allow me to add a variable (ie. example.php?variable=1 ).
It it possible to do this?
thanks in advance,
Greg.
Unless you modified something, out of the box Wordpress will allow you to use GET variables, because it uses them too (for previewing posts).
If you installed something that removed all of the GET parameters, you might want to uninstall that. But out of the box Wordpress will let you use GET parameters.
I have tried both GET and POST with no effect. If you have PHP processing a GET variable on a WP Page, the URL is:
/page/?variable=something
And PHP is not recognizing this at all.
Use add_query_arg function. Codex.

Categories