Search code examples
google-analyticswordpresspermalinks

auto filling custom field for posts in wordpress?


I need to fill a custom field of all my posts in wordpress with a google analtyics URL tagged version of the link to the post. Is there a way to do this automatically and quickly for all posts by using some plugins? I need the tagged URLs of the posts for another plugin that reads data from a custom field. It would be great if I could enter something generic like "generate(permalink)" in the custom field for each post, and then when some other plugin reads this custom field it will actually use the output of the generate function (which tagged the permalink). thanks, B


Solution

  • use this code once:

    $args = array('posts_per_page' => '-1');
    $posts = get_posts($args);
    foreach( $posts as $post ) : setup_postdata($post);
    update_post_meta($post->ID, 'name of CF', 'value of CF');
    endforeach;