It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am using wordpress 3.5, I create a custom post type called order with title supports only.
Now i want that when this order will publish the title text will be order-#ID , (here ID will be the post ID that going to be publish) nothing else if user write something in title it will not publish it just save with value like order-#23 .
Another thing is any other way to hide title input (i don't wanna show title and editor) but save its value when it publish as like order-#265.
You could hook it at save_post and then update the database to reflect the change in title.
Note that I didn't test the code but it should be something like that:
function save_title( $post_id ){
global $wpdb;
$wpdb->update( $wpdb->posts, array( 'post_title' => 'order-#' . $post_id ), array( 'ID' => $post_id ) );
}
add_action( 'save_post', 'save_title');
Related
I've been researching for days and all I want to be able to do is create entries in the ninja form admin listings. Either by submitting custom form (not ninja form generated) or just calling a hook and passing data (data will match actual form fields created in ninja form).
I want to be able to do this so that I can create any type of form layout and still be able to submit to ninja form entry. Or if anyone has any other information on a plugin that can allow me to do such a thing, please share.
In NinjaForms version 3, you probably want to look at this file:
ninja-forms/includes/Actions/Save.php
The process function contains the important bits that may help you:
$sub = Ninja_Forms()->form( $form_id )->sub()->get();
foreach($fields as $field_id => $field_value){
$sub->update_field_value( $field_id, $field_value );
}
$sub->save();
In NinjaForms version 2, it is a little different
$sub_id = Ninja_Forms()->subs()->create( $form_id );
foreach( $form_fields as $field_id => $value ) {
Ninja_Forms()->sub( $sub_id )->add_field( $field_id, $value );
}
Where the $form_fields array would look like:
$form_fields = array(
$fiel_id_1 => $value_1,
$fiel_id_2 => $value_2,
...
);
I know this is is quite a while after the last comment on this post, but it should be noted that if you submit the form this way you will not be able to trigger any notifications. I have spent hours upon hours trying to include different classes and functions and try to rewrite the notifications class locally in my webhook script that was processing my forms, but I can't get it to work. Maybe there is someone smarter than me that can figure it out or maybe one day Ninja Forms will properly build out this functionality in their API. But for right now, if you need notifications this is not a full solution.
I would recommend switching over to Gravity Forms if you are still early enough in your project. Their API does have a submit_form() function that also triggers notifications and action steps. I just wish they would spend some time on their absolutely atrocious interface. I hate everything about their admin UX, but for more complex development things like this, they really are the best option.
Documentation
Can we talk about WordPress revision? How do I save the metadata revision of a WordPress Custom Post Type?
I have searched for it for endless hours today and other days, I have found one decent article about it that I will cite it below. I believe this could be helpful to many, mainly because there is not much out there that talks about this feature and how to save revisions of a meta data field. WordPress revision feature seems to be left behind sometime ago, unfortunately.
My case
In my particular case, I am creating a Wiki-style plugin that manages information of a custom post type. Besides the basic fields of a custom post type ( title, author, content, featured image), I have a few other fields that I would like to keep track of versions.
My attempt
As I already mentioned about, I have found an article by John Blackbourn (and thanks John!) from back in 2012 that pointed me in the right direction. But yet, I can't get it to work. I might be missing something, maybe I have a misconception of how WordPress revisions work, or maybe I just need to sleep on it and it will come to me in the morning. Who knows, but I truly need your help. Here is what I got so far:
To save a metadata revision of a single field, straight from the article mentioned above:
function my_plugin_save_post( $post_id, $post ) {
if ( $parent_id = wp_is_post_revision( $post_id ) ) {
$parent = get_post( $parent_id );
$my_meta = get_post_meta( $parent->ID, 'my_meta', true );
if ( false !== $my_meta )
add_metadata( 'post', $post_id, 'my_meta', $my_meta );
}
} add_action( 'save_post', 'my_plugin_save_post' );
It looks really straight forward, right? But guess what, it fails at the if ( $parent_id) {...} condition. Because $post_id isn't a revision. How is this suppose to work if it is never a revision? I don't get it. I thought the hook 'save_post' sends the current $post_id and not a child-revision. What am I doing wrong?
The save_post hook is fired when you save a post, but it gets triggered not only for the actual post but also for the revision that gets inserted at the same time.
So wp_is_post_revision( $post_id ) will return false when WordPress saves the actual post to the database, and it'll return true when it inserts the revision. This is when the code in the conditional statement will fire.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I could not find a very proper title for my problem.
I have been trying to incorporate a beautiful search bar(http://loopj.com/jquery-tokeninput) in my drupal website. For this to happen I need to create a php callback function, that should be like: www.mysite.com/search/callback?q=var1.
This is a prerequisite and I cannot do otherwise. However, in drupal you set up the Urls in similar to www.mysite.com/search/callback/var1.
Is there a way to achieve the first one in Drupal?
Thanks :-)
EDIT-1:
What I have already done is :
$items['search/callback'] = array(
'title' => 'Search for String',
'description' => 'callback function for search bar',
'page callback' => 'search_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
)
I can recomend you to explore full example for jQuery UI Autocomplete taxonomy terms here: http://xandeadx.ru/blog/drupal/526. It's originally written in Russian but you can easily read code listings and download packed project. I think you can use the same idea of module.
Some notes:
You can't use q get param for your purpose because it is used by Drupal internally. In jQuery Tokeninput you can set another name of param with queryParam option.
I recommend to check any $_GET param with check_plain().
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want build a library function so that when my text comes from database that function filter that text.
Ex : string message= " Hello, world";
so my one function will change the text hello to hi
and another function will change the world to global.
This filter only work if there is any function in my class.
I need this to do in asp.net c#. Is any one have the idea how to do this.
Its not quite clear what you trying to achieve.
But I think you want to do something like this...
var s = YOUR STRING
string[] wordslist = s.Split(' ');
foreach (var word in wordslist )
{
switch (word )
{
case "Hello":
word= word.replace(word,'Hi');
case "World":
etc.....
}
}
I think it will be much easier if you can create database table which hold pair of values.
eg
tblReplace
OldValue NewValue
Hello Hi
World global
So you can do a search for each character with against the OldValue field and if found, you can replace the word with new value..
Hope this helps
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I want to download some files programatically from a remote server.
If you can write the code-snippet in VB, VB.NET, Java, or PHP I can try to solve the rest by myself.
Sample file address:
www.example.com/file1.pdf
www.example.com/file2.pdf
www.example.com/file%20n-1.pdf
It will be helpful if you give solutions to this problem in PHP so I can test in WAMP.
In VB.NET, WebClient makes this trivial:
new WebClient().DownloadFile(url, filename)
In Java, you may use java.net.URL and java.net.URLConnection class methods.
SO Thread - How to download and save a file from internet using Java.
PHP example
<?php
$files = array('file1.pdf', 'file2.pdf', 'filen.pdf');
$remoteBase = 'http://www.site.com/';
$localBase = 'downloads/';
foreach( $files as $f ) {
$fp = fopen($remoteBase.$f, 'rb');
if ( !$fp ) {
echo 'error, ', $f, "\n";
}
else {
file_put_contents($localBase.$f, $fp);
fclose($fp);
}
}