• Resolved Rosemary Senjem

    (@rosemarydesigns)


    Hello,

    First, MANY THANKS for making this plugin.

    Second, I have read and used many of your support answers and still have one question.

    My Goal: Set my custom field called Art_Code to the WP slug, also known as ‘post_name’.

    Why?

    • This is an art gallery. I need to output the Art_Code in a link as a variable to send to the contact form.
    • Everything works except getting the Art_Code to set based on the slug. Other contact links in the header and navigation are carrying the slug variable without a problem.
    • We already have many posts built with the format shortcode inside the post. I know I could rebuild the format in a wp template, but would rather not do all that re-construction if it is not necessary.

    I have this function working well in my theme:

    function the_slug() {
    $post_data = get_post($post->ID, ARRAY_A);
    $slug = $post_data['post_name'];
    return $slug; }

    I have this code working well in my header.php file

    $cfcontactref='';
      if ( have_posts() ) : while ( have_posts() ) : the_post();
     	 $cfcontactref=the_slug();
       endwhile; else:
    	$cfcontactref='';
       endif;

    Template 0 includes this:

    [Art_Code]
    type = text
    code = 0
    editCode=1
    shortCode = true
    valueCount = true
    search = true

    I was guessing that editCode will actually set the default value of Art_Code to be the result of the php in Code 0, combined with Code 1, and it appears that I am incorrect.

    Code 0 is this:
    $value = 'show a code';
    I figure, I need to set it to some text at first.

    Code 1 is this:

    $post_data = get_post($post->ID, ARRAY_A);
    $value = $post_data['post_name'];

    Format 0 (shows inside particular posts) is html for a table that includes this:

    <tr>
    <td colspan="2">[SOLD] <a href="/contact/?cf_field_7=[Art_Code]">Contact us to set up an appointment</a> for viewing and purchasing, or for more information.</td>
    </tr>

    Is there some other way to set the default value by using PHP?
    Is there an error in my:

    • settings
    • assumptions
    • methodology

    Thanks so much,

    Rosie

Viewing 1 replies (of 1 total)
  • Thread Starter Rosemary Senjem

    (@rosemarydesigns)

    I GOT IT TO WORK!!
    Here’s all that was missing:
    readOnly = true

    I was making this field vulnerable to change by allowing it to be edited in the post editing view.

    Now, all is well, the link works, AND I all I need to do with existing files is Update the file (regular OR quick edit method) and it rights itself.

    [Art_Code]
    type = text
    code = 0
    editCode=1
    shortCode = true
    valueCount = true
    search = true
    readOnly = true
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Custom Field Template] Setting Custom Field to Slug data’ is closed to new replies.