• Resolved xter123

    (@xter123)


    Hi,
    I’m trying to loop through products (custom post type) and find one that has a title “High-speed access”. But I’m getting the list of all products in the category instead. Do you have any suggestion for this?

    [loop type='product' category='panora' field_1='product_category' value_1='internet']
    
    [content title=High-speed access" field="title"]
    
    [/loop]

    Thanks.

    http://ww.wp.xz.cn/plugins/custom-content-shortcode/

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    If there’s only one product with that title, then you can use the [content] shortcode by itself.

    This will display the post content of the product post type, with the title:

    [content type="product" title="High-speed access"]

    Or other fields:

    [content type="product" title="High-speed access" field="url"]

    If there’s more than one product with the title “High-speed access”, I would suggest using a category, tag, taxonomy or another field to organize and display products.

    Hmm, reading your question again, maybe I misunderstood. Please give more details, and I’ll see how I can help.

    Thread Starter xter123

    (@xter123)

    Hmm.. What it does basically is selecting all posts with custom field ‘product_category’ equals ‘internet’, but completely ignoring title=”High-speed access” part.

    Plugin Author Eliot Akira

    (@miyarakira)

    By title do you mean post title? If so, is there only only product with that title, or several?

    Thread Starter xter123

    (@xter123)

    There are several posts with the same title, but they are in different categories. That’s why I used loop
    [loop type='product' category='panora' field_1='product_category' value_1='internet']

    Plugin Author Eliot Akira

    (@miyarakira)

    Maybe it will be easier if you had another custom field called speed, for high-speed access or not. Then you can search for it like this:

    [loop type='product' category='panora' field='product_category' value='internet'  field_2="speed" value_2="high-speed access"]
        [content field="title"]
        [content field="url"]
        ...
    [/loop]
    Plugin Author Eliot Akira

    (@miyarakira)

    I think that’s probably not what you had in mind.

    The reason why it’s not working as you want, is because when you specify [content title=”High-speed access”], it will find the first post with the title, regardless of the category, post type, etc.

    The best way it seems is to use some parameter from the loop shortcode to search for the product you want to display.

    Thread Starter xter123

    (@xter123)

    ok, thanks a lot

    Thread Starter xter123

    (@xter123)

    will mark as resolved

    Plugin Author Eliot Akira

    (@miyarakira)

    Currently, there’s no parameter called title for the loop, but I could put it in there for the next update, so you could do something like:

    [loop type='product' category='panora' field='product_category' value='internet' title="High-speed access"]

    It seems like there should be an easier way.. Please let me know if you find a good solution.

    Thread Starter xter123

    (@xter123)

    That would be great!

    Plugin Author Eliot Akira

    (@miyarakira)

    OK, I’ll let you know when I get it implemented.

    Plugin Author Eliot Akira

    (@miyarakira)

    You know, I realized that you may be able to do this already. Please see the query here, the second field and value parameters.

    [loop type='product' category='panora' field='product_category' value='internet'  field_2="post_title" value_2="High-speed access"]
        [content field="title"]
        [content field="url"]
        ...
    [/loop]

    This should display content/fields from all products with category panora, product_category equals internet, and the title is: High-speed access.

    Would that work for you?

    Plugin Author Eliot Akira

    (@miyarakira)

    Please see the update to version 0.4.4. I added the title parameter, so you can do something like:

    [loop type='product' category='panora' title="High-speed access" field='product_category' value='internet']
        [content field="title"]
        [content field="url"]
        ...
    [/loop]
    Thread Starter xter123

    (@xter123)

    Awesome! It works! Thank you!

    The only thing is that title search seems to be case-sensitive (i.e. it doesn’t find any posts for ‘high-speed internet’ but does for ‘High-speed internet’)

    Plugin Author Eliot Akira

    (@miyarakira)

    Sure, I made it so it’s not case-sensitive. 🙂

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Select post by title’ is closed to new replies.