• Resolved herculesnetwork

    (@herculesnetwork)


    how to write the output of this function in field ‘tags’ on post-edit the dasboard the worpress?

    $input = array("neo", "Morpheus", "Trinity", "Cypher", "Tank");
    $rand_keys = array_rand($input, 2);
    $mixnames = $input[$rand_keys[1]];

    Thanks to all.

Viewing 15 replies - 16 through 30 (of 157 total)
  • Thread Starter herculesnetwork

    (@herculesnetwork)

    this question of function run only when I enter the published post and apply refresh on the page, can be corrected by asking the function insert_gen_num run along with another function that I need to click on a button for her to run, but the same problem, are the values not remain on the page after a refreash.

    Moderator bcworkz

    (@bcworkz)

    Sorry for the slow reply, I was offline for a while. I did notice you attempts to reach me outside of this forum. Unfortunately, not only is such contact discouraged, but actually accessing other member’s servers or WP sites as admin is forbidden.

    I can tell you I tested the code I provided on my own server and it worked fine. It ran once when a post was first published and never ran again when the post was edited. If we cannot replicate your issue on our own servers, there is little we in these forums can do to help since accessing other servers is forbidden.

    I cannot imagine how my last code suggestion would alter the keys on every page refresh. Maybe you have other code still active? You should not need any other code. Also note that this code only runs when a post is first created. To test this code, you must create a new post, editing a post would do nothing unless you have other code that is altering the default behavior.

    When testing code, it’s best to use one of the default twenty* themes and disable all unnecessary plugins to remove the chance of outside influence. Additionally, you might be interested to know that I use a completely stock installation on a local server running on my PC, incoming remote requests are rejected at the firewall. If you do much server side coding, it is well worth setting something like this up.

    In any case, try eliminating all other unnecessary code. My code will work as the only code on a simple, custom plugin. Create a new post to confirm the keys are inserted. Anything else you do should not change the keys. I’m sorry I’m not able to help you by accessing your server. Good luck!

    Thread Starter herculesnetwork

    (@herculesnetwork)

    Thanks for the reply ?? I do not know what’s going on, I copy and past your code in my functions.php of my themes, I’am testing in two servers, the free, and my VPS, and on my laptop, and it does not work if I do not call the function within the single.php or content-single .php of themes, and appears below each arros value added, I already cleared all plugins, all themes, and only reintalei common free that already comes pre-installed on wordpress. still not working ta, I’ll clean installation, reinstall wordpress. and I come back here to say.

    Thread Starter herculesnetwork

    (@herculesnetwork)

    Hello again ?? well .. USA is new fresh installation including new vhost on my server, all configuration stock, default installation of wordpress, php 5.4.16 yet this function:

    function insert_gen_num( $post )
    {
      $input = array("Neo ", "Morpheus ", "Trinity ", "Cypher ", "Tank ", "the flash ","superman ","wolverine ", "subzero ","scorpion ");
      $rand_keys = array_rand($input, 5);
      $mixnames = $input[$rand_keys[0]].$input[$rand_keys[1]].$input[$rand_keys[2]].$input[$rand_keys[3]].$input[$rand_keys[4]];
      $post->post_content = $mixnames . $post->post_content;
      $post->post_title = $mixnames . $post->post_title;
      wp_update_post( $post );
    }
    add_action('draft_to_publish', 'insert_gen_num');

    only works if I call it in single.php with insert_gen_num echo;
    and yet, it generates the values ??when I apply f5 first made on the site, it changes all values ??in all lists posts widget Recents posts, it generally changes every f5, but the dashboard everything is normal. I can even make changes and apply f5 that everything is ok, and when I go on post view, I see the perfect post for the first time, but when I press f5, he and every other move to a new sequence of names, and even disappear the changes are only the names. ie, the first visitor in wbsite changes everything already tried two more machine locations, all new, new xampp install, wordpress new install, and no modification or plugin. wordpress 4.4.2

    Thanks again.

    Thread Starter herculesnetwork

    (@herculesnetwork)

    just a comment: I see a thing abou add tags ??
    https://stackoverflow.com/questions/12267422/update-and-add-tags-post-on-save-post-using-wp-update-post

    many guys talk at save_post para add content in post. I don’t know.

    Moderator bcworkz

    (@bcworkz)

    You certainly get an ‘A’ grade for effort!

    There has to be some of your old code active somewhere for F5 to generate keynames. I retested my code using the version you most recently published above on a completely stock WP installation with twentysixteen theme active and no plugins. The code was added to the end of that theme’s functions.php for testing purposes. It’s not generally a good idea to add code to established themes, but this is for temporary proof of concept where all extraneous influence has been eliminated.

    I then created a new page based on the default template. Five key words were inserted in the title and content. Following the view page link, the same keywords remained in place. Pressing F5 multiple times did not change anything. The process was repeated for a new post with the same results.

    I think the old code is active on your theme template files somewhere. Please try switching to twentysixteen and adding my code to the end of the theme’s functions.php file. Deactivate all plugins. Create a new post or page. You should see the keys inserted after you click Publish. View the new post or page. The same keys should still be there. Press F5, nothing should change.

    Once you’ve determined the code works in this environment, you will be more convinced old code exists somewhere. Restore your normal theme. Comment out the add_action() call to ‘draft_to_publish’ to disable my code. I believe you will still observe erroneous keyword behavior due to old code existing somewhere.

    If possible, revert your normal theme back to a state before you attempted any keyword coding. Confirm success by the lack of any new keyword activity. The test posts from the twentysixteen theme test will still have the same five keywords, but new posts should behave normally.

    I suggest adding my code as a simple plugin. Delete my code from where ever it may currently exist. Create a new code page in the /plugins/ folder. Let’s call the plugin ‘Random Keywords’, so the filename should be random-keywords.php. Place the following comment at the top of the page, followed by my code and nothing else. Activate the plugin.

    <?php
    /*
    Plugin Name: Random Keywords
    Description: Generates random keywords for every post
    Author: herculesnetwork
    Version: 0.01a
    License: GNU GPLv3
    */

    You can eventually add any other site specific code to this plugin ??

    If you reverted the theme code properly, the plugin should behave the same as it did in the twentysixteen theme.

    Good luck!

    Thread Starter herculesnetwork

    (@herculesnetwork)

    Thank BCworkz, you have dedicated attention to my topic,

    I must say I saw your function to work for one or two times, but I think very, very strange I do not view this job function, now I do not see it working any time, in any way, not changing values ??every refresh!

    and that the code I copy right, not to have error I always create a text file with my notes and paste the functions and everything is a double bearing

    // Function important

    here the function

    // Function import copy

    here past again,

    all its two functions I have to copy, because sometimes we can change something by accident, so make copies.

    and lately I’ve copied directly here from the topic and used the browser search engine to search for the function with if I wanted to find her sssrsrsr is my technique to get the code is true ??

    on my server, I deleted the vhost, virtualmin, created another vhost (add domain again)

    create a new database by phpmyadmin

    I installed last www.remarpro.com download.

    0 plugin, code 0 at all in stock, even permalinks changed to nomepost as I always do.

    amazing the code not work more, and more impressively still, it’s my personal locahost my laptop with xamp, all new installation, 100% clean, stock, I just did throw the code at the end of the theme functions.php sisxteen, I always use the default theme that is already active in wordpress, and always at the end of code I play any code.

    I do not understand, now I wondered if there was nothing and bad with my server, but also can not be it, because my laptop has a private messenger xampp site, and is also no longer running the code, I was wondering if you are not my browsers that are cached know it. Now I’m even worried about it because I have the impression I saw this code to run at least 2 months amid the My exchanges tabs believe it was this last code I saw running, so when I saw that things started to get weird, now closed everything, and got the attention only to this code, and see what was that on my server, I start to investigate, not yet given reboot it, I’ll try now.
    ??From already thank you very much all your attention and important feedback for me.
    ????Best Regards.

    Thread Starter herculesnetwork

    (@herculesnetwork)

    BCWORKZ, I killed the riddle, I made a plugin and test in various computers, and saw only the second click publish is that the data appears note on your machine only works on the second click publish this because in the first, it makes a draft and in the second he makes a published, and the values are only added in posts in action publish, ie, the second click! because the first action is to draft, as it is now for the first click already been published?
    The fact is: there’s something wrong with this code, because sometimes working sometimes not, it tested in several pcs; I insist creating several posts with the value 1 in the title and nothing else, and one hour it works for later, already tested on various pc after I made plugin.

    Moderator bcworkz

    (@bcworkz)

    Sometimes caching can obscure what code is actually doing when the cache is not properly flushed and updated. However, since you observe this behavior on different machines, this seems unlikely unless they all happen to have the same caching software.

    It doesn’t make sense that clicking publish once only goes to draft and you need to re-click to actually publish. I suppose you could hook ‘transition_post_status’, which passes the current old and new statuses to your callback. Find out what combination works when the post is first published.

    If that combination happens under other circumstances, you will need to go back to storing something in post meta indicating the keys have been inserted and for your script not to add more keys if that something is found.

    Thread Starter herculesnetwork

    (@herculesnetwork)

    I do tests on several different browsers in new facilities, and always are published on the second click, I already sees seen a solution as ‘transition_post_status’ on Google when searched for draft_to_publish, I try to make this substitution and also not worked, and also with self-draft and publish_post and not worked, I’m not too lazy to click publish for the second time, but the big problem is that I have auto posting plugin is need these data into the first act of publication, but only go if I enter in all posts and click publish, I have a plugin that makes mass import post, and it would be good if those entered already together, put a solution in a new topic that does this, the data come along with posting this plugin, just do not understand it is the best way to do it, but in my preliminary tests everything is ok.
    I thought of cache, I thought about time schedules, set up the schedule of my wordpress site tests, and do not know if I need to set the timezone of my server also because I read that could be related because not published immediately even when configured in wordpress to to set immediately in the post edit.
    ?Thank BCworkZ the backs feeds ??

    Thread Starter herculesnetwork

    (@herculesnetwork)

    I fumbled with that part to say that only in the second clicko post status changes from draft tp publish, sometimes changes the first time no, this independent to the contents appear or not, but always appear in the second click publish, never on first. and I need than to enter in the first act of publishing in order to work together with a plugin, and so my code in another post some work with the plugin, remembering again that all tests that make in your code are in purar installation and clean, and local servers and new servers in the vps. all 100% clean, stock, when I say that not work with pugin why not inject the values ??along with the plugin, but if I click the second time it injects, it has the same behavior as the other machines that are 100% in stock every way, just, php, mysql, wp, stock browsers, and always the same behavior, enter the data on the second click, when I thought that sometimes worked and sometimes did not work, it’s because sometimes I clicked one second time the laptop and not noticed a second act of click publish be having clicked on the button new post dashboard as to test I create several and several posts filling only one character in the post title name to post fast and see the result, and always on the second click, the plugin works well, and anywhere. and second click, not fit to put the data together with the auto posting plugin. I created a plugin with your code, and description I put a reminder for me to know that he only carries on the second click. soon I will already know each other plugin it does not serve to work because it would give a lot of work and time to get into all the posts to have to click one second time. thanks again. THX ??

    Thread Starter herculesnetwork

    (@herculesnetwork)

    BCworks, eu tenho +2000 posts em um website, eu adoraria fazer um 1 copia do titles para o incio dos posts, isso pode ser feito puxando uma tag
    <?php the_title(); ?> em content-single.php, faz examente o que eu disse, mas nao aparece o valor no dashboard no post edit mode ?? você têm alguma ideia [emotion:embarrassed] ??

    Thread Starter herculesnetwork

    (@herculesnetwork)

    I tried it at least to try to add the new posts in the publication of the act:

    add_filter( 'wp_insert_post_data' , 'add_string_on_publish' , '999', 2 );
    function add_string_on_publish( $post_content,  $postarr='' ) {
        $post_content['post_content'] .= $post_title;
        return $post_content;
    }

    without success ??

    this is a function that I use to apply string .= ‘text here’;

    Thread Starter herculesnetwork

    (@herculesnetwork)

    sorry from my Portuguese language:

    BCworks, I have +2000 posts on a website, I’d love to make one copy of the titles to the beginning of the posts, it can be done by pulling a tag
    <? Php the_title (); ?> In content-single.php, makes exactly what I said, but not the value appears on the dashboard in the post edit mode ?? you have any idea [emotion: embarrassed] ??

    Moderator bcworkz

    (@bcworkz)

    Something you said caused me to realize what’s going on! You have to put something in both the title and content fields before clicking publish, otherwise WP thinks you are not done yet and saves it as draft. It doesn’t need to be much, a single character will do.

    We’ve focused on adding keys to new posts. How does this relate to the posts you already have? Do you wish to add keys to those? Or make new posts from the existing titles with added keys?

    If you are working from existing data, there is no need to hook ‘draft_to_post’. You could create a script that steps through the data and does what is needed for each item, all without any intervention from you, other than initiating the code to start.

    For example, use get_posts() to get all published posts. Step through the returned posts with foreach (). In each iteration, get the title with something like $post->post_title. Call the key generation function to get the keys and append the post title to them. Do something similar for $post->post_content.

    You can create a new post by first doing unset($post->ID); then using the current $post object, call wp_insert_post(). The function will assign a new ID and use the content of the $post object to comprise the new post’s data.

    You can add keys to existing posts in a single script by using the above logic, except do not unset the ID, and call wp_update_post() with the current post object. Just be sure to thoroughly test your script on a limited set of data before turning it loose on your entire DB. Also backup your DB before the full run, just in case ??

Viewing 15 replies - 16 through 30 (of 157 total)
  • The topic ‘how to write the output of this function in field 'tags' on post-edit’ is closed to new replies.