You are probably gluten-intolerant. I suggest you try cutting all gluten out of your diet for at least a month and see if your gut problems go away. It requires that you read labels on things all the time. I am gluten intolerant myself, and my life improved a lot when I went gluten-free. You have to avoid anything made with wheat, rye, barley, or triticale. Oats are fine unless they are processed in a facility that uses wheat.
However, it did not reduce my chronic pain to go gluten free. It might for you, though, because we are all different. The things that affect me are alcohol, which I now drink only very rarely and only one drink, and never beer (gluten) or wine (makes my pain terrible the next day), and sugar consumption. I find I can eat only a small amount of sugar, and not daily. Experiment and see what helps you. But you have to give each thing you try at least a month to see if it is working for you or not, and only try one thing at a time or you will not ever know what helps.